diff --git a/src/Promise/Declaration/Extractor/Methods.php b/src/Promise/Declaration/Extractor/Methods.php index 46cde4b..80e8e4e 100644 --- a/src/Promise/Declaration/Extractor/Methods.php +++ b/src/Promise/Declaration/Extractor/Methods.php @@ -60,6 +60,7 @@ public function __construct( /** * @param \ReflectionClass $reflection * @return array + * @throws \ReflectionException */ public function getMethods(\ReflectionClass $reflection): array { @@ -198,6 +199,14 @@ private function packParams(\ReflectionMethod $method): array $param->setDefault($parameter->getDefaultValue()); } + if ($parameter->isVariadic()) { + $param->makeVariadic(); + } + + if ($parameter->isPassedByReference()) { + $param->makeByRef(); + } + $type = $this->defineParamReturnType($parameter); if ($type !== null) { $param->setType($type); diff --git a/tests/Promise/ProxyPrinter/Methods/Fixtures/ArgsFixture.php b/tests/Promise/ProxyPrinter/Methods/Fixtures/ArgsFixture.php index f264415..2b2996f 100644 --- a/tests/Promise/ProxyPrinter/Methods/Fixtures/ArgsFixture.php +++ b/tests/Promise/ProxyPrinter/Methods/Fixtures/ArgsFixture.php @@ -7,6 +7,10 @@ class ArgsFixture { + public function referencedSetter(string $a, &$b, int $c): void + { + } + public function typedSetter(string $a, $b, int $c): void { } @@ -15,4 +19,8 @@ public function typedSetter(string $a, $b, int $c): void public function defaultsSetter(string $a, $b = [], int $c = 3, bool $d): void { } + + public function variadicSetter($a, string ...$b): void + { + } } diff --git a/tests/Promise/ProxyPrinter/Methods/MethodArgsTest.php b/tests/Promise/ProxyPrinter/Methods/MethodArgsTest.php index d8c24fe..a103356 100644 --- a/tests/Promise/ProxyPrinter/Methods/MethodArgsTest.php +++ b/tests/Promise/ProxyPrinter/Methods/MethodArgsTest.php @@ -14,30 +14,50 @@ class MethodArgsTest extends BaseProxyPrinterTest */ public function testHasArgType(): void { - $classname = Fixtures\ArgsFixture::class; - $as = self::NS . __CLASS__ . __LINE__; - $reflection = new \ReflectionClass($classname); + $output = $this->makeOutput(Fixtures\ArgsFixture::class, self::NS . __CLASS__ . __LINE__); - $parent = Declarations::createParentFromReflection($reflection); - $class = Declarations::createClassFromName($as, $parent); + $this->assertStringContainsString('typedSetter(string $a, $b, int $c)', $output); + } - $output = $this->make($reflection, $class, $parent); - $output = ltrim($output, 'makeOutput(Fixtures\ArgsFixture::class, self::NS . __CLASS__ . __LINE__); - $this->assertFalse(class_exists($class->getFullName())); + //Long syntax by default + $this->assertStringContainsString('defaultsSetter(string $a, $b = array(), int $c = 3, bool $d)', $output); + } - eval($output); + /** + * @throws \ReflectionException + */ + public function testVariadicArg(): void + { + $output = $this->makeOutput(Fixtures\ArgsFixture::class, self::NS . __CLASS__ . __LINE__); - $this->assertStringContainsString('typedSetter(string $a, $b, int $c)', $output); + $this->assertStringContainsString('public function variadicSetter($a, string ...$b)', $output); } /** * @throws \ReflectionException */ - public function testArgDefaults(): void + public function testReferencedArg(): void + { + $output = $this->makeOutput(Fixtures\ArgsFixture::class, self::NS . __CLASS__ . __LINE__); + + $this->assertStringContainsString('public function referencedSetter(string $a, &$b, int $c)', $output); + } + + /** + * @param string $classname + * @param string $as + * @return string + * @throws \ReflectionException + */ + private function makeOutput(string $classname, string $as): string { - $classname = Fixtures\ArgsFixture::class; - $as = self::NS . __CLASS__ . __LINE__; $reflection = new \ReflectionClass($classname); $parent = Declarations::createParentFromReflection($reflection); @@ -50,12 +70,6 @@ public function testArgDefaults(): void eval($output); - //Long syntax by default - $this->assertStringContainsString('defaultsSetter(string $a, $b = array(), int $c = 3, bool $d)', $output); - } - - public function testArgVariadic(): void - { - $this->assertTrue(true); + return $output; } }