Repository: Roave/BetterReflection (php)

Issue:
ReflectionNamedType::isBuiltIn incorrect behavior 
I have noticed that [`ReflectionNamedType::isBuiltIn`](https://github.com/Roave/BetterReflection/blob/5.1.x/src/Reflection/ReflectionNamedType.php#L60) is working incorrectly, and it looks like it was broken after #750 merged.

Neither `self`, `parent`, `static` is built-in types in PHP according original PHP Reflections.

The last commit I can find which looked like it worked like should be this 3419b0f28b6d80f1af6bece384a125e5350bbb3d [`ReflectionNamedType::isBuiltIn`](https://github.com/Roave/BetterReflection/blob/3419b0f28b6d80f1af6bece384a125e5350bbb3d/src/Reflection/Adapter/ReflectionNamedType.php#L43)

I am not sure if removing them from the list is a good thing because I think those are used somewhere else. I also think maybe having a test to test the list of types against real Reflection to see if it's really is a built-in type would be nice to prevent this in the future.


Pull request description:
`static`, `self` and `parent` are not built-in in ReflectionNamedType adapter
Fixes #961

Patch:
diff --git a/src/Reflection/Adapter/ReflectionNamedType.php b/src/Reflection/Adapter/ReflectionNamedType.php
index 74484422..3a265a27 100644
--- a/src/Reflection/Adapter/ReflectionNamedType.php
+++ b/src/Reflection/Adapter/ReflectionNamedType.php
@@ -36,6 +36,12 @@ final class ReflectionNamedType extends CoreReflectionNamedType
 
     public function isBuiltin(): bool
     {
+        $type = strtolower($this->betterReflectionType->getName());
+
+        if ($type === 'self' || $type === 'parent' || $type === 'static') {
+            return false;
+        }
+
         return $this->betterReflectionType->isBuiltin();
     }
 }


Test patch:
diff --git a/test/unit/Reflection/Adapter/ReflectionNamedTypeTest.php b/test/unit/Reflection/Adapter/ReflectionNamedTypeTest.php
index b54beaed..b982d508 100644
--- a/test/unit/Reflection/Adapter/ReflectionNamedTypeTest.php
+++ b/test/unit/Reflection/Adapter/ReflectionNamedTypeTest.php
@@ -4,11 +4,14 @@ declare(strict_types=1);
 
 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;
@@ -86,4 +89,30 @@ class ReflectionNamedTypeTest extends TestCase
         $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());
+    }
 }