mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
use Attribute feature of PHP-Parser to avoid dealing with dynamic properties
This commit is contained in:
parent
d54032078d
commit
bee5b69f7f
@ -314,7 +314,7 @@ class ScopeAnalyzer
|
||||
}
|
||||
);
|
||||
|
||||
if ($has_default_terminator || isset($stmt->allMatched)) {
|
||||
if ($has_default_terminator || $stmt->getAttribute('allMatched', false)) {
|
||||
return array_values(array_unique(array_merge($control_actions, $all_case_actions)));
|
||||
}
|
||||
|
||||
|
@ -199,8 +199,7 @@ class SwitchAnalyzer
|
||||
}
|
||||
}
|
||||
|
||||
/** @psalm-suppress UndefinedPropertyAssignment */
|
||||
$stmt->allMatched = true;
|
||||
$stmt->setAttribute('allMatched', true);
|
||||
} elseif ($switch_scope->possibly_redefined_vars) {
|
||||
foreach ($switch_scope->possibly_redefined_vars as $var_id => $type) {
|
||||
if (isset($context->vars_in_scope[$var_id])) {
|
||||
|
@ -1011,8 +1011,7 @@ class FunctionCallAnalyzer extends CallAnalyzer
|
||||
// fall through
|
||||
}
|
||||
} else {
|
||||
/** @psalm-suppress UndefinedPropertyAssignment */
|
||||
$stmt->pure = true;
|
||||
$stmt->setAttribute('pure', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,9 @@ class MethodCallPurityAnalyzer
|
||||
}
|
||||
} elseif (($method_storage->mutation_free
|
||||
|| ($method_storage->external_mutation_free
|
||||
&& (isset($stmt->var->external_mutation_free) || isset($stmt->var->pure))))
|
||||
&& ($stmt->var->getAttribute('external_mutation_free', false)
|
||||
|| $stmt->var->getAttribute('pure', false))
|
||||
))
|
||||
&& !$context->inside_unset
|
||||
) {
|
||||
if ($method_storage->mutation_free
|
||||
@ -89,12 +91,10 @@ class MethodCallPurityAnalyzer
|
||||
&& !$method_storage->assertions
|
||||
&& !$method_storage->if_true_assertions
|
||||
) {
|
||||
/** @psalm-suppress UndefinedPropertyAssignment */
|
||||
$stmt->memoizable = true;
|
||||
$stmt->setAttribute('memoizable', true);
|
||||
|
||||
if ($method_storage->immutable) {
|
||||
/** @psalm-suppress UndefinedPropertyAssignment */
|
||||
$stmt->pure = true;
|
||||
$stmt->setAttribute('pure', true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -118,8 +118,7 @@ class MethodCallPurityAnalyzer
|
||||
// fall through
|
||||
}
|
||||
} elseif (!$method_storage->mutation_free_inferred) {
|
||||
/** @psalm-suppress UndefinedPropertyAssignment */
|
||||
$stmt->pure = true;
|
||||
$stmt->setAttribute('pure', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -213,8 +213,7 @@ class MethodCallAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\
|
||||
}
|
||||
|
||||
if ($result->can_memoize) {
|
||||
/** @psalm-suppress UndefinedPropertyAssignment */
|
||||
$stmt->memoizable = true;
|
||||
$stmt->setAttribute('memoizable', true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -551,8 +551,7 @@ class NewAnalyzer extends \Psalm\Internal\Analyzer\Statements\Expression\CallAna
|
||||
}
|
||||
|
||||
if ($storage->external_mutation_free) {
|
||||
/** @psalm-suppress UndefinedPropertyAssignment */
|
||||
$stmt->external_mutation_free = true;
|
||||
$stmt->setAttribute('external_mutation_free', true);
|
||||
$stmt_type = $statements_analyzer->node_data->getType($stmt);
|
||||
|
||||
if ($stmt_type) {
|
||||
|
@ -201,7 +201,7 @@ class ExpressionIdentifier
|
||||
) {
|
||||
$config = \Psalm\Config::getInstance();
|
||||
|
||||
if ($config->memoize_method_calls || isset($stmt->memoizable)) {
|
||||
if ($config->memoize_method_calls || $stmt->getAttribute('memoizable', false)) {
|
||||
$lhs_var_name = self::getArrayVarId(
|
||||
$stmt->var,
|
||||
$this_class_name,
|
||||
|
@ -38,12 +38,12 @@ class CheckTrivialExprVisitor extends PhpParser\NodeVisitorAbstract
|
||||
if (($node instanceof PhpParser\Node\Expr\FuncCall
|
||||
|| $node instanceof PhpParser\Node\Expr\MethodCall
|
||||
|| $node instanceof PhpParser\Node\Expr\StaticCall)
|
||||
&& isset($node->pure)
|
||||
&& $node->getAttribute('pure', false)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($node instanceof PhpParser\Node\Expr\New_ && isset($node->external_mutation_free)) {
|
||||
if ($node instanceof PhpParser\Node\Expr\New_ && $node->getAttribute('external_mutation_free', false)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ class NodeDataProvider implements \Psalm\NodeTypeProvider
|
||||
{
|
||||
$node_type = $this->getType($node);
|
||||
|
||||
return ($node_type && $node_type->reference_free) || isset($node->pure);
|
||||
return ($node_type && $node_type->reference_free) || $node->getAttribute('pure', false);
|
||||
}
|
||||
|
||||
public function clearNodeOfTypeAndAssertions(Node\Expr $node) : void
|
||||
|
Loading…
x
Reference in New Issue
Block a user