Skip to content

Commit

Permalink
Merge pull request #962 from kukulich/builint-types
Browse files Browse the repository at this point in the history
`static`, `self` and `parent` are not built-in in ReflectionNamedType adapter
  • Loading branch information
Ocramius committed Jan 9, 2022
2 parents 97b524f + 9dc93cc commit 0802bfb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Reflection/Adapter/ReflectionNamedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public function allowsNull(): bool

public function isBuiltin(): bool
{
$type = strtolower($this->betterReflectionType->getName());

if ($type === 'self' || $type === 'parent' || $type === 'static') {
return false;
}

return $this->betterReflectionType->isBuiltin();
}
}
29 changes: 29 additions & 0 deletions test/unit/Reflection/Adapter/ReflectionNamedTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

namespace Roave\BetterReflectionTest\Reflection\Adapter;

use PhpParser\Node;
use PHPUnit\Framework\TestCase;
use ReflectionClass as CoreReflectionClass;
use ReflectionNamedType as CoreReflectionNamedType;
use Roave\BetterReflection\Reflection\Adapter\ReflectionNamedType as ReflectionNamedTypeAdapter;
use Roave\BetterReflection\Reflection\ReflectionMethod as BetterReflectionMethod;
use Roave\BetterReflection\Reflection\ReflectionNamedType as BetterReflectionNamedType;
use Roave\BetterReflection\Reflector\Reflector;

use function array_combine;
use function array_map;
Expand Down Expand Up @@ -86,4 +89,30 @@ public function testAdapterMethods(string $methodName, ?string $expectedExceptio
$adapter = new ReflectionNamedTypeAdapter($reflectionStub, false);
$adapter->{$methodName}(...$args);
}

public function dataNotBuildin(): array
{
return [
['self'],
['sElF'],
['static'],
['sTaTiC'],
['parent'],
['PaReNt'],
];
}

/**
* @dataProvider dataNotBuildin
*/
public function testIsNotBuiltin(string $type): void
{
$reflector = $this->createMock(Reflector::class);
$owner = $this->createMock(BetterReflectionMethod::class);

$betterReflectionNamedType = new BetterReflectionNamedType($reflector, $owner, new Node\Name($type));
$reflectionTypeAdapter = new ReflectionNamedTypeAdapter($betterReflectionNamedType, false);

self::assertFalse($reflectionTypeAdapter->isBuiltin());
}
}

0 comments on commit 0802bfb

Please sign in to comment.