Skip to content

Commit

Permalink
AutoloadSourceLocator - do not execute autoloader if the class alread…
Browse files Browse the repository at this point in the history
…y exists but is evaled

Closes phpstan/phpstan#7960
  • Loading branch information
ondrejmirtes committed Jun 7, 2023
1 parent cee6672 commit 32b889d
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,13 @@ public function locateIdentifier(Reflector $reflector, Identifier $identifier):
$startLine = $this->startLineByClass[$loweredClassName];
} else {
$reflection = $this->getReflectionClass($identifier->getName());
if ($reflection !== null && $reflection->getStartLine() !== false) {
if (
$reflection !== null
&& $reflection->getStartLine() !== false
&& is_string($reflection->getFileName())
&& is_file($reflection->getFileName())
&& $reflection->getFileName() === $this->presentSymbols['classes'][$loweredClassName]
) {
$startLine = $reflection->getStartLine();
}
}
Expand Down Expand Up @@ -283,18 +289,7 @@ public function locateIdentifiersByType(Reflector $reflector, IdentifierType $id
private function getReflectionClass(string $className): ?ReflectionClass
{
if (class_exists($className, false) || interface_exists($className, false) || trait_exists($className, false)) {
$reflection = new ReflectionClass($className);
$filename = $reflection->getFileName();

if (!is_string($filename)) {
return null;
}

if (!is_file($filename)) {
return null;
}

return $reflection;
return new ReflectionClass($className);
}

return null;
Expand Down Expand Up @@ -323,6 +318,9 @@ private function locateClassByName(string $className): ?array
if (!is_string($filename)) {
return null;
}
if (!is_file($filename)) {
return null;
}

return [[$filename], $reflection->getName(), $reflection->getStartLine() !== false ? $reflection->getStartLine() : null];
}
Expand Down

0 comments on commit 32b889d

Please sign in to comment.