Skip to content

Commit

Permalink
Get rid of annoying "on an unknown class ReflectionEnum" error on PHP…
Browse files Browse the repository at this point in the history
… < 8.1
  • Loading branch information
ondrejmirtes committed Sep 29, 2023
1 parent dcfa3b1 commit 2b9af36
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 310 deletions.
310 changes: 0 additions & 310 deletions build/enum-adapter-errors.neon
Original file line number Diff line number Diff line change
@@ -1,180 +1,10 @@
parameters:
ignoreErrors:
-
message: "#^Call to method getInterfaceNames\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Analyser/NodeScopeResolver.php

-
message: "#^Call to method getStartLine\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 3
path: ../src/Analyser/NodeScopeResolver.php

-
message: "#^Call to method getStartLine\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Rules/Classes/DuplicateClassDeclarationRule.php

-
message: "#^Call to method getInterfaceNames\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Analyser/TypeSpecifier.php

-
message: "#^Call to method getMethod\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/PhpDoc/PhpDocInheritanceResolver.php

-
message: "#^Call to method hasConstant\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/PhpDoc/PhpDocInheritanceResolver.php

-
message: "#^Call to method hasMethod\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/PhpDoc/PhpDocInheritanceResolver.php

-
message: "#^Call to method hasProperty\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/PhpDoc/PhpDocInheritanceResolver.php

-
message: "#^Call to method getReflectionConstants\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/PhpDoc/TypeNodeResolver.php

-
message: "#^Call to method getAttributes\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 3
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method getBackingType\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method getValueExpression\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnumBackedCase\\.$#"
count: 2
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method getCase\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method getCases\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method getConstructor\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method getDocComment\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method getFileName\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method getInterfaceNames\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 2
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method getInterfaces\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 2
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method getName\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method getParentClass\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 8
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method getReflectionConstant\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 2
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method getTraits\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 2
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method hasCase\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method hasConstant\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method implementsInterface\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method isAbstract\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method isBacked\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 2
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method isEnum\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method isFinal\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method isInterface\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 2
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method isInternal\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method isReadOnly\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method isSubclassOf\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method isTrait\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum not found\\.$#"
count: 5
Expand Down Expand Up @@ -205,26 +35,6 @@ parameters:
count: 1
path: ../src/Reflection/ClassReflection.php

-
message: "#^Call to method getMethod\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ConstructorsHelper.php

-
message: "#^Call to method getName\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ConstructorsHelper.php

-
message: "#^Call to method hasMethod\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/ConstructorsHelper.php

-
message: "#^Call to method getName\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 2
path: ../src/Reflection/Native/NativeMethodReflection.php

-
message: "#^Method PHPStan\\\\Reflection\\\\Php\\\\BuiltinMethodReflection\\:\\:getDeclaringClass\\(\\) has invalid return type PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
Expand All @@ -249,123 +59,3 @@ parameters:
message: "#^Method PHPStan\\\\Reflection\\\\Php\\\\NativeBuiltinMethodReflection\\:\\:getDeclaringClass\\(\\) has invalid return type PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Reflection/Php/NativeBuiltinMethodReflection.php

-
message: "#^Call to method getConstructor\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 2
path: ../src/Reflection/Php/PhpClassReflectionExtension.php

-
message: "#^Call to method getMethod\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 3
path: ../src/Reflection/Php/PhpClassReflectionExtension.php

-
message: "#^Call to method getName\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 4
path: ../src/Reflection/Php/PhpClassReflectionExtension.php

-
message: "#^Call to method getProperty\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 3
path: ../src/Reflection/Php/PhpClassReflectionExtension.php

-
message: "#^Call to method hasMethod\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 3
path: ../src/Reflection/Php/PhpClassReflectionExtension.php

-
message: "#^Call to method hasProperty\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 2
path: ../src/Reflection/Php/PhpClassReflectionExtension.php

-
message: "#^Call to method isTrait\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 2
path: ../src/Reflection/Php/PhpClassReflectionExtension.php

-
message: "#^Call to method getName\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 2
path: ../src/Reflection/Php/PhpMethodReflection.php

-
message: "#^Call to method getTraitAliases\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 2
path: ../src/Reflection/Php/PhpMethodReflection.php

-
message: "#^Call to method getMethods\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Rules/Api/ApiClassConstFetchRule.php

-
message: "#^Call to method getShortName\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Rules/Cast/InvalidCastRule.php

-
message: "#^Call to method getTraitAliases\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Rules/Methods/IllegalConstructorStaticCallRule.php

-
message: "#^Call to method getMethods\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Rules/Methods/MissingMethodImplementationRule.php

-
message: "#^Call to method getMethods\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Rules/Methods/MissingMagicSerializationMethodsRule.php

-
message: "#^Call to method isFinal\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 2
path: ../src/Type/Constant/ConstantStringType.php

-
message: "#^Call to method getInterfaceNames\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Type/DynamicReturnTypeExtensionRegistry.php

-
message: "#^Call to method getProperties\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Type/ObjectType.php

-
message: "#^Call to method getStartLine\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 2
path: ../src/Type/ObjectType.php

-
message: "#^Call to method isFinal\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 3
path: ../src/Type/ObjectType.php

-
message: "#^Call to method isUserDefined\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Type/ObjectType.php

-
message: "#^Call to method getProperty\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../tests/PHPStan/Analyser/AnalyserIntegrationTest.php

-
message: "#^Call to method getProperty\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/PhpDoc/PhpDocInheritanceResolver.php

-
message: "#^Call to method getName\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../tests/PHPStan/Reflection/ClassReflectionTest.php

-
message: "#^Call to method getProperties\\(\\) on an unknown class PHPStan\\\\BetterReflection\\\\Reflection\\\\Adapter\\\\ReflectionEnum\\.$#"
count: 1
path: ../src/Node/ClassStatementsGatherer.php
16 changes: 16 additions & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,22 @@ services:
arguments:
classes: %universalObjectCratesClasses%

-
class: PHPStan\Reflection\PHPStan\NativeReflectionEnumReturnDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
arguments:
className: PHPStan\Reflection\ClassReflection
methodName: getNativeReflection

-
class: PHPStan\Reflection\PHPStan\NativeReflectionEnumReturnDynamicReturnTypeExtension
tags:
- phpstan.broker.dynamicMethodReturnTypeExtension
arguments:
className: PHPStan\Reflection\Php\BuiltinMethodReflection
methodName: getDeclaringClass

-
class: PHPStan\Reflection\ReflectionProvider\ReflectionProviderProvider
factory: PHPStan\Reflection\ReflectionProvider\LazyReflectionProviderProvider
Expand Down
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);
}

}

0 comments on commit 2b9af36

Please sign in to comment.