Skip to content

Commit

Permalink
tv bump 2 (#45)
Browse files Browse the repository at this point in the history
* misc

* report class name

* misc
  • Loading branch information
TomasVotruba committed Sep 5, 2024
1 parent 354eb9d commit 9c52692
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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>\|T of object, string given#'
21 changes: 17 additions & 4 deletions src/PhpParser/NodeVisitor/FindClassConstFetchNodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 9c52692

Please sign in to comment.