From 9295c14309696af1cf3e43f7f31bbc6dd255d7ba Mon Sep 17 00:00:00 2001 From: Jan Lam Date: Tue, 15 Sep 2026 11:23:31 +0200 Subject: [PATCH] Don't fully-qualify "object" as a return/param type Same class of bug as the earlier "static" fix: "object" is a pseudo-type, not a class name, so emitting "\object" in generated interfaces is invalid PHP. Fixes generation for methods like addMutation(object $x): void. Co-Authored-By: Claude Sonnet 5 --- src/ReflectionTypeInterface.php | 1 + test/Fixtures/ExtendedReturnTypeInterface.php | 4 ++-- test/Fixtures/ReturnTypeInterface.php | 4 ++-- test/ReflectionTypeTest.php | 17 +++++++++++++++++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/ReflectionTypeInterface.php b/src/ReflectionTypeInterface.php index d2e8b07..ea6ddd4 100644 --- a/src/ReflectionTypeInterface.php +++ b/src/ReflectionTypeInterface.php @@ -13,6 +13,7 @@ interface ReflectionTypeInterface 'void', 'self', 'static', + 'object', 'array', 'callable', 'iterable', diff --git a/test/Fixtures/ExtendedReturnTypeInterface.php b/test/Fixtures/ExtendedReturnTypeInterface.php index 36d09bc..acd9033 100644 --- a/test/Fixtures/ExtendedReturnTypeInterface.php +++ b/test/Fixtures/ExtendedReturnTypeInterface.php @@ -44,9 +44,9 @@ public function callableMethod(): ?callable; public function streamMethod(): ?\Hostnet\Component\EntityPlugin\Fixtures\resource; /** - * @return \Hostnet\Component\EntityPlugin\Fixtures\object|null + * @return object|null */ - public function objectMethod(): ?\object; + public function objectMethod(): ?object; /** * @return int|null diff --git a/test/Fixtures/ReturnTypeInterface.php b/test/Fixtures/ReturnTypeInterface.php index ed55e65..249a6d2 100644 --- a/test/Fixtures/ReturnTypeInterface.php +++ b/test/Fixtures/ReturnTypeInterface.php @@ -44,9 +44,9 @@ public function callableMethod(): callable; public function streamMethod(): \Hostnet\Component\EntityPlugin\Fixtures\resource; /** - * @return \Hostnet\Component\EntityPlugin\Fixtures\object + * @return object */ - public function objectMethod(): \object; + public function objectMethod(): object; /** * @return int diff --git a/test/ReflectionTypeTest.php b/test/ReflectionTypeTest.php index 215cbec..99bbe8b 100644 --- a/test/ReflectionTypeTest.php +++ b/test/ReflectionTypeTest.php @@ -33,6 +33,11 @@ class ReflectionTypeTest extends TestCase */ private $t4; + /** + * @var ReflectionType + */ + private $t5; + private function method(array $param = null, \Exception $param_2): void { // for testing only; @@ -48,6 +53,11 @@ private function fluentMethod(): static return $this; } + private function objectParamMethod(object $param_3): void + { + // for testing only; + } + protected function setUp(): void { if (PHP_MAJOR_VERSION < 7) { @@ -58,6 +68,7 @@ protected function setUp(): void $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()); + $this->t5 = new ReflectionType((new \ReflectionParameter([$this, 'objectParamMethod'], 'param_3'))->getType()); } public function testGetName(): void @@ -73,6 +84,12 @@ public function testGetNameDoesNotQualifyStaticReturnType(): void $this->assertSame('static', $this->t4->getName()); } + public function testGetNameDoesNotQualifyObjectType(): void + { + // "object" is a pseudo-type, not a class name — qualifying it as "\object" is invalid PHP. + $this->assertSame('object', $this->t5->getName()); + } + public function testAllowsNull(): void { $this->assertTrue($this->t1->allowsNull());