Skip to content

Commit

Permalink
[BUGFIX] Re-Allow Extbase Reflection for self
Browse files Browse the repository at this point in the history
Due to a bug in #94001 the Extbase Reflection of
"self" did not work anymore.

Resolves: #94076
Releases: master, 10.4
Change-Id: I3658d8175661621a493ac15d19238b4f0d60eb64
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69072
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
bmack authored and lolli42 committed May 6, 2021
1 parent c1e224d commit 897c87d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions typo3/sysext/extbase/Classes/Reflection/ClassSchema.php
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions typo3/sysext/extbase/Tests/Unit/Reflection/ClassSchemaTest.php
Expand Up @@ -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
*/
Expand Down

0 comments on commit 897c87d

Please sign in to comment.