Esempio n. 1
0
 /**
  * @return \nochso\WriteMe\Reflection\Parameter[]
  */
 public function getParametersWithoutCall()
 {
     $parameters = [];
     foreach (array_slice($this->method->getParameters(), 1) as $param) {
         $parameters[] = new Parameter($param);
     }
     return $parameters;
 }
 /**
  * {@inheritDoc}
  */
 public function getParameters()
 {
     $parameters = $this->betterReflectionMethod->getParameters();
     $wrappedParameters = [];
     foreach ($parameters as $key => $parameter) {
         $wrappedParameters[$key] = new ReflectionParameter($parameter);
     }
     return $wrappedParameters;
 }
Esempio n. 3
0
 private function isCallable(Reflection\ReflectionMethod $method)
 {
     if (!$method->isPublic()) {
         return false;
     }
     if ($method->getNumberOfRequiredParameters() < 1) {
         return false;
     }
     $firstParameter = $method->getParameters()[0];
     if ((string) $firstParameter->getTypeHint() !== '\\' . Call::class) {
         return false;
     }
     return true;
 }
 private function assertSameMethodAttributes(\ReflectionMethod $original, ReflectionMethod $stubbed)
 {
     $this->assertSame(array_map(function (\ReflectionParameter $parameter) {
         return $parameter->getDeclaringFunction()->getName() . '.' . $parameter->getName();
     }, $original->getParameters()), array_map(function (ReflectionParameter $parameter) {
         return $parameter->getDeclaringFunction()->getName() . '.' . $parameter->getName();
     }, $stubbed->getParameters()));
     foreach ($original->getParameters() as $parameter) {
         $this->assertSameParameterAttributes($parameter, $stubbed->getParameter($parameter->getName()));
     }
     $this->assertSame($original->isPublic(), $stubbed->isPublic());
     $this->assertSame($original->isPrivate(), $stubbed->isPrivate());
     $this->assertSame($original->isProtected(), $stubbed->isProtected());
     $this->assertSame($original->returnsReference(), $stubbed->returnsReference());
     $this->assertSame($original->isStatic(), $stubbed->isStatic());
     $this->assertSame($original->isFinal(), $stubbed->isFinal());
 }
Esempio n. 5
0
 /**
  *
  *
  * @param ReflectionMethod $reflection
  * @return Method
  */
 public static function fromReflection(ReflectionMethod $reflection)
 {
     // gestion du type
     //       $type = implode('|', $reflection->getDocBlockTypeStrings());
     //
     // construction
     $method = new static($reflection->getName(), [], $reflection->getBodyCode());
     // docblock
     $docblock = new \phpDocumentor\Reflection\DocBlock($reflection->getDocComment());
     $method->setSummary($docblock->getShortDescription());
     $method->setDescription($docblock->getLongDescription());
     // gestion des modifiers
     $reflection->isPrivate() ? $method->enablePrivate() : $method->disablePrivate();
     $reflection->isProtected() ? $method->enableProtected() : $method->disabledProtected();
     $reflection->isPublic() ? $method->enablePublic() : $method->disablePublic();
     $reflection->isStatic() ? $method->enableStatic() : $method->disableStatic();
     $reflection->isFinal() ? $method->enableFinal() : $method->disableFinal();
     foreach ($reflection->getParameters() as $parameter) {
         $method->addParameter(Parameter::fromReflection($parameter));
     }
     return $method;
 }
 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);
 }