diff --git a/typo3/sysext/extbase/Classes/Reflection/ClassSchema.php b/typo3/sysext/extbase/Classes/Reflection/ClassSchema.php index ace512ef1d3b..b50bd2c45a62 100644 --- a/typo3/sysext/extbase/Classes/Reflection/ClassSchema.php +++ b/typo3/sysext/extbase/Classes/Reflection/ClassSchema.php @@ -384,6 +384,11 @@ protected function reflectMethods(\ReflectionClass $reflectionClass): void if ($reflectionType->isBuiltin()) { $this->methods[$methodName]['params'][$parameterName]['array'] = $reflectionType->getName() === 'array'; // compat $this->methods[$methodName]['params'][$parameterName]['type'] = ltrim($reflectionType->getName(), '\\'); + } elseif ($reflectionType->getName() === 'self') { + // In addition, self cannot be resolved by "new \ReflectionClass('self')", + // so treat this as a reference to the current class + $this->methods[$methodName]['params'][$parameterName]['class'] = $reflectionClass->getName(); + $this->methods[$methodName]['params'][$parameterName]['type'] = ltrim($reflectionClass->getName(), '\\'); } else { // This is mainly to confirm that the class exists. If it doesn't, a ReflectionException // will be thrown. It's not the ideal way of doing so, but it maintains the existing API diff --git a/typo3/sysext/extbase/Tests/Unit/Reflection/ClassSchemaTest.php b/typo3/sysext/extbase/Tests/Unit/Reflection/ClassSchemaTest.php index bc7d11c7b727..0144f717b9dd 100644 --- a/typo3/sysext/extbase/Tests/Unit/Reflection/ClassSchemaTest.php +++ b/typo3/sysext/extbase/Tests/Unit/Reflection/ClassSchemaTest.php @@ -295,6 +295,31 @@ public function foo(string $foo) self::assertSame('string', $classSchema->getMethod('foo')->getParameter('foo')->getType()); } + /** + * @test + */ + public function classSchemaCanHandleSelfMethodReturnTypes(): void + { + $class = new class() { + public function __construct(self $copy = null) + { + } + public function injectCopy(self $copy): void + { + } + public function foo($copy): self + { + } + public function bar(self $copy): void + { + } + }; + + $classSchema = new ClassSchema(get_class($class)); + self::assertSame(get_class($class), $classSchema->getMethod('injectCopy')->getParameter('copy')->getType()); + self::assertSame(get_class($class), $classSchema->getMethod('bar')->getParameter('copy')->getType()); + } + /** * @test */