1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Make memoisation more universal

This commit is contained in:
Matthew Brown 2018-04-28 13:25:44 -04:00
parent da6209276f
commit 496256c2a5
2 changed files with 21 additions and 21 deletions

View File

@ -83,27 +83,6 @@ class AssertionFinder
return $if_types;
}
if ($conditional instanceof PhpParser\Node\Expr\MethodCall
&& $conditional->name instanceof PhpParser\Node\Identifier
&& !$conditional->args
) {
$config = \Psalm\Config::getInstance();
if ($config->memoize_method_calls) {
$lhs_var_name = ExpressionChecker::getArrayVarId(
$conditional->var,
$this_class_name,
$source
);
if ($lhs_var_name) {
$method_var_id = $lhs_var_name . '->' . strtolower($conditional->name->name) . '()';
$if_types[$method_var_id] = '!falsy';
return $if_types;
}
}
}
if ($conditional instanceof PhpParser\Node\Expr\BooleanNot) {
$if_types_to_negate = self::getAssertions(
$conditional->expr,

View File

@ -723,6 +723,27 @@ class ExpressionChecker
return $object_id . '->' . $stmt->name;
}
if ($stmt instanceof PhpParser\Node\Expr\MethodCall
&& $stmt->name instanceof PhpParser\Node\Identifier
&& !$stmt->args
) {
$config = \Psalm\Config::getInstance();
if ($config->memoize_method_calls) {
$lhs_var_name = self::getArrayVarId(
$stmt->var,
$this_class_name,
$source
);
if (!$lhs_var_name) {
return null;
}
return $lhs_var_name . '->' . strtolower($stmt->name->name) . '()';
}
}
return self::getVarId($stmt, $this_class_name, $source);
}