diff --git a/src/ReflectionTypeInterface.php b/src/ReflectionTypeInterface.php index 0c5ab40..d2e8b07 100644 --- a/src/ReflectionTypeInterface.php +++ b/src/ReflectionTypeInterface.php @@ -12,6 +12,7 @@ interface ReflectionTypeInterface 'null', 'void', 'self', + 'static', 'array', 'callable', 'iterable', diff --git a/test/ReflectionTypeTest.php b/test/ReflectionTypeTest.php index 614be14..215cbec 100644 --- a/test/ReflectionTypeTest.php +++ b/test/ReflectionTypeTest.php @@ -28,6 +28,11 @@ class ReflectionTypeTest extends TestCase */ private $t3; + /** + * @var ReflectionType + */ + private $t4; + private function method(array $param = null, \Exception $param_2): void { // for testing only; @@ -38,6 +43,11 @@ private function php8method(string|int $union_param): string|int return $union_param; } + private function fluentMethod(): static + { + return $this; + } + protected function setUp(): void { if (PHP_MAJOR_VERSION < 7) { @@ -47,6 +57,7 @@ protected function setUp(): void $this->t1 = new ReflectionType((new \ReflectionParameter([$this, 'method'], 'param'))->getType()); $this->t2 = new ReflectionType((new \ReflectionParameter([$this, 'method'], 'param_2'))->getType()); $this->t3 = new ReflectionType((new \ReflectionParameter([$this, 'php8method'], 'union_param'))->getType()); + $this->t4 = new ReflectionType((new \ReflectionMethod($this, 'fluentMethod'))->getReturnType()); } public function testGetName(): void @@ -56,6 +67,12 @@ public function testGetName(): void $this->assertSame('string|int', $this->t3->getName()); } + public function testGetNameDoesNotQualifyStaticReturnType(): void + { + // "static" is a reserved word, not a class name — qualifying it as "\static" is invalid PHP. + $this->assertSame('static', $this->t4->getName()); + } + public function testAllowsNull(): void { $this->assertTrue($this->t1->allowsNull());