-
Notifications
You must be signed in to change notification settings - Fork 472
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get rid of annoying "on an unknown class ReflectionEnum" error on PHP…
… < 8.1
- Loading branch information
1 parent
dcfa3b1
commit 2b9af36
Showing
3 changed files
with
56 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/Reflection/PHPStan/NativeReflectionEnumReturnDynamicReturnTypeExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\Reflection\PHPStan; | ||
|
||
use PhpParser\Node\Expr\MethodCall; | ||
use PHPStan\Analyser\Scope; | ||
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionClass; | ||
use PHPStan\Php\PhpVersion; | ||
use PHPStan\Reflection\MethodReflection; | ||
use PHPStan\Type\DynamicMethodReturnTypeExtension; | ||
use PHPStan\Type\ObjectType; | ||
use PHPStan\Type\Type; | ||
|
||
class NativeReflectionEnumReturnDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension | ||
{ | ||
|
||
public function __construct(private PhpVersion $phpVersion, private string $className, private string $methodName) | ||
{ | ||
} | ||
|
||
public function getClass(): string | ||
{ | ||
return $this->className; | ||
} | ||
|
||
public function isMethodSupported(MethodReflection $methodReflection): bool | ||
{ | ||
return $methodReflection->getName() === $this->methodName; | ||
} | ||
|
||
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): ?Type | ||
{ | ||
if ($this->phpVersion->supportsEnums()) { | ||
return null; | ||
} | ||
|
||
return new ObjectType(ReflectionClass::class); | ||
} | ||
|
||
} |