diff --git a/composer.json b/composer.json index 8aed49020..76803d8a9 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "rector/rector": "^1.0", "shipmonk/composer-dependency-analyser": "^1.7", "symplify/easy-coding-standard": "^12.3", - "tomasvotruba/class-leak": "^0.2", + "tomasvotruba/class-leak": "^0.2.16", "tomasvotruba/type-coverage": "^0.3.1", "tracy/tracy": "^2.10" }, diff --git a/phpstan.neon b/phpstan.neon index aa5d9fd58..7a95ff2dc 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -18,3 +18,5 @@ parameters: ignoreErrors: # unrelated - '#Parameter \#1 \$className of class Rector\\SwissKnife\\ValueObject\\ClassConstant constructor expects class-string, string given#' + + - '#Parameter \#1 \$objectOrClass of class ReflectionClass constructor expects class-string\|T of object, string given#' diff --git a/src/PhpParser/NodeVisitor/FindClassConstFetchNodeVisitor.php b/src/PhpParser/NodeVisitor/FindClassConstFetchNodeVisitor.php index 039972760..4c31191f4 100644 --- a/src/PhpParser/NodeVisitor/FindClassConstFetchNodeVisitor.php +++ b/src/PhpParser/NodeVisitor/FindClassConstFetchNodeVisitor.php @@ -85,7 +85,7 @@ public function enterNode(Node $node): Node|int|null throw new NotImplementedYetException('@todo'); } - if (class_exists($className) || interface_exists($className)) { + if ($this->doesClassExist($className)) { // is class from /vendor? we can skip it if ($this->isVendorClassName($className)) { return null; @@ -96,7 +96,7 @@ public function enterNode(Node $node): Node|int|null return null; } - throw new NotImplementedYetException(); + throw new NotImplementedYetException($className . '::' . $constantName); } public function leaveNode(Node $node): ?Node @@ -120,8 +120,8 @@ public function getClassConstantFetches(): array private function isVendorClassName(string $className): bool { - if (! class_exists($className) && ! interface_exists($className) && ! trait_exists($className)) { - throw new ShouldNotHappenException(); + if (! $this->doesClassExist($className)) { + throw new ShouldNotHappenException(sprintf('Class "%s" could not be found', $className)); } $reflectionClass = new ReflectionClass($className); @@ -154,4 +154,17 @@ private function getClassName(): string return $namespaceName->toString(); } + + private function doesClassExist(string $className): bool + { + if (class_exists($className)) { + return true; + } + + if (interface_exists($className)) { + return true; + } + + return trait_exists($className); + } }