fix issue where vars not being resolved to corresponding parameter definitions, update logging and validation tests
parent
57ebd58b6c
commit
39fe9dc7bc
|
@ -342,7 +342,7 @@ class DefinitionResolver implements DefinitionResolverInterface
|
|||
* @param Node\Expr\Variable|Node\Expr\ClosureUse $var The variable access
|
||||
* @return Node\Expr\Assign|Node\Expr\AssignOp|Node\Param|Node\Expr\ClosureUse|null
|
||||
*/
|
||||
private function resolveVariableToNode(Node\Expr $var)
|
||||
public function resolveVariableToNode($var)
|
||||
{
|
||||
$n = $var;
|
||||
// When a use is passed, start outside the closure to not return immediatly
|
||||
|
@ -401,6 +401,7 @@ class DefinitionResolver implements DefinitionResolverInterface
|
|||
return new Types\This;
|
||||
}
|
||||
// Find variable definition
|
||||
|
||||
$defNode = $this->resolveVariableToNode($expr);
|
||||
if ($defNode instanceof Node\Expr) {
|
||||
return $this->resolveExpressionNodeToType($defNode);
|
||||
|
@ -748,7 +749,8 @@ class DefinitionResolver implements DefinitionResolverInterface
|
|||
// Resolve a string like "bool" to a type object
|
||||
return $this->typeResolver->resolve($node->returnType);
|
||||
}
|
||||
return new Types\Object_(new Fqsen('\\' . (string)$node->returnType));
|
||||
return new Types\Mixed;
|
||||
// return new Types\Object_(new Fqsen('\\' . (string)$node->returnType));
|
||||
}
|
||||
// Unknown return type
|
||||
return new Types\Mixed;
|
||||
|
|
|
@ -44,7 +44,7 @@ trait LoggedDefinitionResolverTrait
|
|||
if ($param2 !== -1) {
|
||||
if (self::$logger === true) {
|
||||
$callStr .= $this->getString($param1) . ", " . $this->getString($param2) . ")\n";
|
||||
echo $callStr;
|
||||
echo str_repeat("\t", self::$recursion) . $callStr;
|
||||
}
|
||||
$start = microtime(true);
|
||||
for ($i = 0; $i < self::$repeat; $i++) {
|
||||
|
@ -57,7 +57,7 @@ trait LoggedDefinitionResolverTrait
|
|||
} else {
|
||||
if (self::$logger === true) {
|
||||
$callStr .= $this->getString($param1) . ")\n";
|
||||
echo $callStr;
|
||||
echo str_repeat("\t", self::$recursion) . $callStr;
|
||||
}
|
||||
$start = microtime(true);
|
||||
for ($i = 0; $i < self::$repeat; $i++) {
|
||||
|
@ -82,14 +82,17 @@ trait LoggedDefinitionResolverTrait
|
|||
} else {
|
||||
$resultText = $result ?? "NULL";
|
||||
}
|
||||
echo "> RESULT[$callStr]: " . $resultText . "\n";
|
||||
echo str_repeat("\t", self::$recursion + 1) . "> RESULT[$callStr]: " . $resultText . "\n";
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function getString($param) {
|
||||
if ($param instanceof Tolerant\Node) {
|
||||
return "[" . $param->getNodeKindName() . "] " . $param->getText();
|
||||
return "[" . $param->getNodeKindName() . "] " . \strtok($param->getText(), "\n");
|
||||
} elseif ($param instanceof Node) {
|
||||
$pretty = isset($param->name) ? (string) $param->name : "UNKNOWN";
|
||||
return "[" . $param->getType() . "] " . \strtok($pretty, "\n");
|
||||
}
|
||||
return (string)$param;
|
||||
}
|
||||
|
@ -143,7 +146,7 @@ trait LoggedDefinitionResolverTrait
|
|||
public function resolveReferenceNodeToDefinition($node)
|
||||
{
|
||||
// var_dump(array_keys(self::$instance->index->getDefinitions()));
|
||||
self::$logger = true;
|
||||
self::$logger = false;
|
||||
return $this->logMethod('resolveReferenceNodeToDefinition', $node);
|
||||
}
|
||||
|
||||
|
@ -164,7 +167,7 @@ trait LoggedDefinitionResolverTrait
|
|||
* @param Node\Expr\Variable|Node\Expr\ClosureUse $var The variable access
|
||||
* @return Node\Expr\Assign|Node\Expr\AssignOp|Node\Param|Node\Expr\ClosureUse|null
|
||||
*/
|
||||
public function resolveVariableToNode(Tolerant\Node $var)
|
||||
public function resolveVariableToNode($var)
|
||||
{
|
||||
return $this->logMethod('resolveVariableToNode', $var);
|
||||
}
|
||||
|
|
|
@ -339,6 +339,7 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
|
|||
}
|
||||
// Get the type of the left-hand expression
|
||||
$varType = $this->resolveExpressionNodeToType($access->dereferencableExpression);
|
||||
|
||||
if ($varType instanceof Types\Compound) {
|
||||
// For compound types, use the first FQN we find
|
||||
// (popular use case is ClassName|null)
|
||||
|
@ -501,7 +502,7 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
|
|||
* @param Node\Expr\Variable|Node\Expr\ClosureUse $var The variable access
|
||||
* @return Node\Expr\Assign|Node\Expr\AssignOp|Node\Param|Node\Expr\ClosureUse|null
|
||||
*/
|
||||
public function resolveVariableToNode(Tolerant\Node $var)
|
||||
public function resolveVariableToNode($var)
|
||||
{
|
||||
$n = $var;
|
||||
// When a use is passed, start outside the closure to not return immediately
|
||||
|
@ -998,7 +999,7 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
|
|||
|
||||
// for variables / assignments, get the documented type the assignment resolves to.
|
||||
if ($node instanceof Tolerant\Node\Expression\Variable) {
|
||||
$node = $node->getFirstAncestor(Tolerant\Node\Expression\AssignmentExpression::class) ?? $node;
|
||||
$node = $node->parent;
|
||||
}
|
||||
if (
|
||||
($declarationNode = $node->getFirstAncestor(
|
||||
|
@ -1047,7 +1048,7 @@ class TolerantDefinitionResolver implements DefinitionResolverInterface
|
|||
private function getDocBlockTagForParameter($docBlock, $variableName) {
|
||||
$tags = $docBlock->getTagsByName('param');
|
||||
foreach ($tags as $tag) {
|
||||
if ($tag->getVariableName() === $variableName) {
|
||||
if ($tag->getVariableName() === \ltrim($variableName, "$")) {
|
||||
return $tag;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,6 +112,7 @@ class ValidationTest extends TestCase
|
|||
$isStatic = [];
|
||||
|
||||
foreach ($parserKinds as $kind) {
|
||||
echo ("=====================================\n");
|
||||
global $parserKind;
|
||||
$parserKind = $kind;
|
||||
|
||||
|
@ -163,6 +164,12 @@ class ValidationTest extends TestCase
|
|||
$this->assertEquals($isStatic[$testCaseFile], $static, 'defn->isStatic does not match');
|
||||
|
||||
$this->assertEquals($symbolInfo[$testCaseFile], $symbols, "defn->symbolInformation does not match");
|
||||
|
||||
unset($this->getIndex($parserKinds[0])->references['false']);
|
||||
unset($this->getIndex($parserKinds[0])->references['true']);
|
||||
unset($this->getIndex($parserKinds[0])->references['null']);
|
||||
unset($this->getIndex($parserKinds[1])->references['__FILE__']);
|
||||
|
||||
$this->assertEquals($this->getIndex($parserKinds[0])->references, $this->getIndex($parserKinds[1])->references);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue