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:
parent
da6209276f
commit
496256c2a5
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user