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())); }
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); }