Skip to content

Commit 5dc4cf3

Browse files
committed
Work around Rector bug
1 parent 306fb02 commit 5dc4cf3

File tree

6 files changed

+20
-29
lines changed

6 files changed

+20
-29
lines changed

build/enum-adapter-errors-7.3.neon

Lines changed: 0 additions & 12 deletions
This file was deleted.

build/enum-adapter-errors.neon

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Parameter \\#9 \\$reflection of class PHPStan\\\\Reflection\\\\ClassReflection constructor expects ReflectionClass, PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionClass\\|PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum given\\.$#"
5-
count: 1
6-
path: ../src/Reflection/BetterReflection/BetterReflectionProvider.php
7-
8-
-
9-
message: "#^Parameter \\#9 \\$reflection of class PHPStan\\\\Reflection\\\\ClassReflection constructor expects ReflectionClass, PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionClass\\|PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum given\\.$#"
10-
count: 1
11-
path: ../src/Analyser/NodeScopeResolver.php
12-
133
-
144
message: "#^Class ReflectionEnum not found\\.$#"
155
count: 1

build/ignore-by-php-version.neon.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525

2626
if (PHP_VERSION_ID < 80000) {
2727
$config = array_merge_recursive($config, $adapter->load(__DIR__ . '/enum-adapter-errors.neon'));
28-
if (PHP_VERSION_ID < 70400) {
29-
$config = array_merge_recursive($config, $adapter->load(__DIR__ . '/enum-adapter-errors-7.3.neon'));
30-
}
3128
}
3229

3330
$config['parameters']['phpVersion'] = PHP_VERSION_ID;

phpstan-baseline.neon

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ parameters:
1515
count: 1
1616
path: src/Analyser/NodeScopeResolver.php
1717

18+
-
19+
message: "#^Parameter \\#9 \\$reflection of class PHPStan\\\\Reflection\\\\ClassReflection constructor expects ReflectionClass, object given\\.$#"
20+
count: 1
21+
path: src/Analyser/NodeScopeResolver.php
22+
1823
-
1924
message: "#^Anonymous function has an unused use \\$container\\.$#"
2025
count: 1
@@ -128,6 +133,11 @@ parameters:
128133
count: 1
129134
path: src/Reflection/BetterReflection/BetterReflectionProvider.php
130135

136+
-
137+
message: "#^Parameter \\#9 \\$reflection of class PHPStan\\\\Reflection\\\\ClassReflection constructor expects ReflectionClass, object given\\.$#"
138+
count: 1
139+
path: src/Reflection/BetterReflection/BetterReflectionProvider.php
140+
131141
-
132142
message: "#^Parameter \\#2 \\$node of method PHPStan\\\\BetterReflection\\\\SourceLocator\\\\Ast\\\\Strategy\\\\NodeToReflection\\:\\:__invoke\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\ArrowFunction\\|PhpParser\\\\Node\\\\Expr\\\\Closure\\|PhpParser\\\\Node\\\\Expr\\\\FuncCall\\|PhpParser\\\\Node\\\\Stmt\\\\Class_\\|PhpParser\\\\Node\\\\Stmt\\\\Const_\\|PhpParser\\\\Node\\\\Stmt\\\\Enum_\\|PhpParser\\\\Node\\\\Stmt\\\\Function_\\|PhpParser\\\\Node\\\\Stmt\\\\Interface_\\|PhpParser\\\\Node\\\\Stmt\\\\Trait_, PhpParser\\\\Node\\\\Stmt\\\\ClassLike given\\.$#"
133143
count: 2

src/Analyser/NodeScopeResolver.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
use PhpParser\Node\Stmt\Unset_;
5050
use PhpParser\Node\Stmt\While_;
5151
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionClass;
52-
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionEnum;
52+
use PHPStan\BetterReflection\Reflection\ReflectionEnum;
5353
use PHPStan\BetterReflection\Reflector\Reflector;
5454
use PHPStan\BetterReflection\SourceLocator\Ast\Strategy\NodeToReflection;
5555
use PHPStan\BetterReflection\SourceLocator\Located\LocatedSource;
@@ -137,6 +137,7 @@
137137
use function array_pop;
138138
use function array_reverse;
139139
use function array_slice;
140+
use function base64_decode;
140141
use function count;
141142
use function in_array;
142143
use function is_array;
@@ -1483,6 +1484,8 @@ private function createAstClassReflection(Node\Stmt\ClassLike $stmt, string $cla
14831484
throw new ShouldNotHappenException();
14841485
}
14851486

1487+
$enumAdapter = base64_decode('UEhQU3RhblxCZXR0ZXJSZWZsZWN0aW9uXFJlZmxlY3Rpb25cQWRhcHRlclxSZWZsZWN0aW9uRW51bQ==', true);
1488+
14861489
return new ClassReflection(
14871490
$this->reflectionProvider,
14881491
$this->fileTypeMapper,
@@ -1492,7 +1495,7 @@ private function createAstClassReflection(Node\Stmt\ClassLike $stmt, string $cla
14921495
$this->classReflectionExtensionRegistryProvider->getRegistry()->getPropertiesClassReflectionExtensions(),
14931496
$this->classReflectionExtensionRegistryProvider->getRegistry()->getMethodsClassReflectionExtensions(),
14941497
$betterReflectionClass->getName(),
1495-
$betterReflectionClass instanceof \PHPStan\BetterReflection\Reflection\ReflectionEnum && PHP_VERSION_ID >= 80000 ? new ReflectionEnum($betterReflectionClass) : new ReflectionClass($betterReflectionClass),
1498+
$betterReflectionClass instanceof ReflectionEnum && PHP_VERSION_ID >= 80000 ? new $enumAdapter($betterReflectionClass) : new ReflectionClass($betterReflectionClass),
14961499
null,
14971500
null,
14981501
null,

src/Reflection/BetterReflection/BetterReflectionProvider.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
use PHPStan\BetterReflection\Identifier\Exception\InvalidIdentifierName;
1010
use PHPStan\BetterReflection\NodeCompiler\Exception\UnableToCompileNode;
1111
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionClass;
12-
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionEnum;
1312
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionFunction;
1413
use PHPStan\BetterReflection\Reflection\Exception\NotAClassReflection;
1514
use PHPStan\BetterReflection\Reflection\Exception\NotAnInterfaceReflection;
15+
use PHPStan\BetterReflection\Reflection\ReflectionEnum;
1616
use PHPStan\BetterReflection\Reflector\Exception\IdentifierNotFound;
1717
use PHPStan\BetterReflection\Reflector\Reflector;
1818
use PHPStan\BetterReflection\SourceLocator\Located\LocatedSource;
@@ -46,6 +46,7 @@
4646
use ReflectionParameter;
4747
use function array_key_exists;
4848
use function array_map;
49+
use function base64_decode;
4950
use function sprintf;
5051
use function strtolower;
5152
use const PHP_VERSION_ID;
@@ -164,6 +165,8 @@ public function getClass(string $className): ClassReflection
164165
return $this->classReflections[$reflectionClassName];
165166
}
166167

168+
$enumAdapter = base64_decode('UEhQU3RhblxCZXR0ZXJSZWZsZWN0aW9uXFJlZmxlY3Rpb25cQWRhcHRlclxSZWZsZWN0aW9uRW51bQ==', true);
169+
167170
$classReflection = new ClassReflection(
168171
$this->reflectionProviderProvider->getReflectionProvider(),
169172
$this->fileTypeMapper,
@@ -173,7 +176,7 @@ public function getClass(string $className): ClassReflection
173176
$this->classReflectionExtensionRegistryProvider->getRegistry()->getPropertiesClassReflectionExtensions(),
174177
$this->classReflectionExtensionRegistryProvider->getRegistry()->getMethodsClassReflectionExtensions(),
175178
$reflectionClass->getName(),
176-
$reflectionClass instanceof \PHPStan\BetterReflection\Reflection\ReflectionEnum && PHP_VERSION_ID >= 80000 ? new ReflectionEnum($reflectionClass) : new ReflectionClass($reflectionClass),
179+
$reflectionClass instanceof ReflectionEnum && PHP_VERSION_ID >= 80000 ? new $enumAdapter($reflectionClass) : new ReflectionClass($reflectionClass),
177180
null,
178181
null,
179182
$this->stubPhpDocProvider->findClassPhpDoc($reflectionClass->getName()),

0 commit comments

Comments
 (0)