Skip to content

Commit

Permalink
OptimizedSingleFileSourceLocator::locateIdentifiersByType() - support…
Browse files Browse the repository at this point in the history
… constants
  • Loading branch information
ondrejmirtes committed Oct 26, 2022
1 parent 3961f7c commit 9914301
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,50 @@ public function locateIdentifiersByType(Reflector $reflector, IdentifierType $id
}
}

if ($identifierType->isConstant()) {
$constantNodes = $fetchedNodesResult->getConstantNodes();
foreach ($constantNodes as $constantNodesArray) {
foreach ($constantNodesArray as $fetchedConstantNode) {
$constantNode = $fetchedConstantNode->getNode();

if ($constantNode instanceof Const_) {
foreach ($constantNode->consts as $constPosition => $const) {
if ($const->namespacedName === null) {
throw new ShouldNotHappenException();
}

$constantReflection = $nodeToReflection->__invoke(
$reflector,
$constantNode,
$fetchedConstantNode->getLocatedSource(),
$fetchedConstantNode->getNamespace(),
$constPosition,
);
if (!$constantReflection instanceof ReflectionConstant) {
throw new ShouldNotHappenException();
}

$reflections[] = $constantReflection;
}

continue;
}

$constantReflection = $nodeToReflection->__invoke(
$reflector,
$constantNode,
$fetchedConstantNode->getLocatedSource(),
$fetchedConstantNode->getNamespace(),
);
if (!$constantReflection instanceof ReflectionConstant) {
throw new ShouldNotHappenException();
}

$reflections[] = $constantReflection;
}
}
}

return $reflections;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,13 @@ public function dataForIdenifiersByType(): iterable
],
'constants' => [
new IdentifierType(IdentifierType::IDENTIFIER_CONSTANT),
[],
[
'ANOTHER_NAME',
'ConstFile\ANOTHER_NAME',
'ConstFile\TABLE_NAME',
'OPTIMIZED_SFSL_OBJECT_CONSTANT',
'const_with_dir_const',
],
__DIR__ . '/data/const.php',
],
];
Expand Down

0 comments on commit 9914301

Please sign in to comment.