From 9d6939226e77c21446155c2f0404f7be867e6463 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Sun, 23 Aug 2020 13:10:47 -0400 Subject: [PATCH] Static property fetching is bad --- .../Expression/Fetch/StaticPropertyFetchAnalyzer.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php index 5055192ac..36d81b347 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php @@ -176,6 +176,8 @@ class StaticPropertyFetchAnalyzer ); } + $project_analyzer = $statements_analyzer->getProjectAnalyzer(); + if ($context->mutation_free) { if (IssueBuffer::accepts( new \Psalm\Issue\ImpureStaticProperty( @@ -186,6 +188,12 @@ class StaticPropertyFetchAnalyzer )) { // fall through } + } elseif ($codebase->alter_code + && isset($project_analyzer->getIssuesToFix()['MissingPureAnnotation']) + && $statements_analyzer->getSource() + instanceof \Psalm\Internal\Analyzer\FunctionLikeAnalyzer + ) { + $statements_analyzer->getSource()->inferred_impure = true; } if ($var_id && $context->hasVariable($var_id, $statements_analyzer)) {