Fetch an array of all methods for this class.
public getMethods ( ) : BetterReflection\Reflection\ReflectionMethod[] | ||
Результат | BetterReflection\Reflection\ReflectionMethod[] |
/** * {@inheritDoc} */ public function getMethods($filter = null) { $methods = $this->betterReflectionClass->getMethods(); $wrappedMethods = []; foreach ($methods as $key => $method) { $wrappedMethods[$key] = new ReflectionMethod($method); } return $wrappedMethods; }
public function methods() : Methods { return new Methods($this->name(), array_map(function (ReflectionMethod $method) { $returnType = $this->typeFactory->create($this->reflector, $method->getReturnType() ? $method->getReturnType()->getTypeObject() : new Mixed(), $method->getDocBlockReturnTypes(), $method->getReturnType() ? $method->getReturnType()->allowsNull() : false); $parameters = array_map(function (ReflectionParameter $parameter) { return new Parameter($parameter, $this->typeFactory->create($this->reflector, $parameter->getTypeHint(), $parameter->getDocBlockTypeStrings(), $parameter->allowsNull()), $parameter->getPosition(), $parameter->isOptional()); }, $method->getParameters()); return new Method($method, $this->annotations->scanForAnnotations($method->getDocComment(), $this->fileName(), $this->imports), new Parameters($this->name() . '::' . $method->getName(), $parameters), $returnType); }, $this->reflectionClass->getMethods())); }
/** * getVisibleMethods returns only the methods that are visible according to `api.visibility`. * * @param \BetterReflection\Reflection\ReflectionClass $class * * @return \BetterReflection\Reflection\ReflectionMethod[] */ public function getVisibleMethods(ReflectionClass $class) { try { $methods = $class->getMethods(); } catch (IdentifierNotFound $e) { $methods = $class->getImmediateMethods(); } return array_filter($methods, [$this, 'isMethodVisible']); }
private function assertSameClassAttributes(\ReflectionClass $original, ReflectionClass $stubbed) { $this->assertSame($original->getName(), $stubbed->getName()); $internalParent = $original->getParentClass(); $betterParent = $stubbed->getParentClass(); $internalParentName = $internalParent ? $internalParent->getName() : null; $betterParentName = $betterParent ? $betterParent->getName() : null; $this->assertSame($internalParentName, $betterParentName); $originalMethods = $original->getMethods(); $originalMethodNames = array_map(function (\ReflectionMethod $method) { return $method->getName(); }, $originalMethods); $stubbedMethodNames = array_map(function (ReflectionMethod $method) { return $method->getName(); }, $stubbed->getMethods()); sort($originalMethodNames); sort($stubbedMethodNames); $this->assertSame($originalMethodNames, $stubbedMethodNames); $this->assertEquals($original->getConstants(), $stubbed->getConstants()); foreach ($originalMethods as $method) { $this->assertSameMethodAttributes($method, $stubbed->getMethod($method->getName())); } }
function it_might_be_invokable(ReflectionClass $reflectionClass, ReflectionMethod $method, AnnotationScanner $annotations, TypeFactory $typeFactory, Type $type, Annotations $methodAnnotations) { $reflectionClass->getName()->willReturn('MyClass'); $method->getName()->willReturn('__invoke'); $method->getReturnType()->willReturn(null); $method->getDocBlockReturnTypes()->willReturn([]); $method->getParameters()->willReturn([]); $method->getDocComment()->willReturn(''); $reflectionClass->getMethods()->willReturn([$method]); $annotations->scanForAnnotations(Argument::any(), Argument::any(), $this->imports)->willReturn($methodAnnotations); $typeFactory->create(Argument::any(), Argument::any(), Argument::any(), Argument::any())->willReturn($type); $this->isInvokable()->shouldBe(true); $reflectionClass->getMethods()->willReturn([]); $this->isInvokable()->shouldBe(false); }