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