private function getMatchingFunctionNode(array $locatedFunctionNodes, IFunctionReflection $reflection)
{
$locationHash = $reflection->getLocation()->getHash();
if (empty($locatedFunctionNodes[$locationHash])) {
throw InvalidFunctionException::invalidFunctionMessage('Cannot parse function, the function could not be located', $reflection->getInnerReflection());
}
// If multiple functions defined on a single line we
// perform all possible resolution to resolve the conflict.
// Magic constants / scopes are resolved in parameter expressions
// to allow matching of functions with these special constants in
// default values.
/** @var $matchedFunctionsByLocation LocatedFunctionNode[] */
$matchedFunctionsByLocation = $locatedFunctionNodes[$locationHash];
$functionSignature = $reflection->getSignature();
$fullyMatchedFunctions = [];
foreach ($matchedFunctionsByLocation as $matchedFunction) {
$magicData = $reflection->resolveMagic($matchedFunction->getDeclaration());
$resolvedMatchedFunctionSignature = $matchedFunction->getSignature()->resolveMagic($magicData);
if ($functionSignature->getHash() === $resolvedMatchedFunctionSignature->getHash()) {
$fullyMatchedFunctions[] = $matchedFunction;
}
}
if (empty($fullyMatchedFunctions)) {
throw InvalidFunctionException::invalidFunctionMessage('Cannot parse function, the function\'s signature could not be matched', $reflection->getInnerReflection());
} elseif (count($fullyMatchedFunctions) > 1) {
throw InvalidFunctionException::invalidFunctionMessage('Cannot parse function, %d ambiguous functions are defined on the same line ' . 'with identical signatures', $reflection->getInnerReflection(), count($locatedFunctionNodes[$locationHash]));
}
return $fullyMatchedFunctions[0];
}