diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php index 8b277f8e62e..9e61c6a1a23 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php @@ -312,12 +312,21 @@ private static function handleMicDrop( if (!$post_if_context->collect_initializations && !$post_if_context->collect_mutations && $statements_analyzer->getFilePath() === $statements_analyzer->getRootFilePath() - && (!(($parent_source = $statements_analyzer->getSource()) - instanceof \Psalm\Internal\Analyzer\FunctionLikeAnalyzer) - || !$parent_source->getSource() instanceof \Psalm\Internal\Analyzer\TraitAnalyzer) ) { - $codebase = $statements_analyzer->getCodebase(); - $codebase->analyzer->decrementMixedCount($statements_analyzer->getFilePath()); + $parent_source = $statements_analyzer->getSource(); + + $functionlike_storage = $parent_source instanceof \Psalm\Internal\Analyzer\FunctionLikeAnalyzer + ? $parent_source->getFunctionLikeStorage() + : null; + + if (!$parent_source instanceof \Psalm\Internal\Analyzer\FunctionLikeAnalyzer + || (!$parent_source->getSource() instanceof \Psalm\Internal\Analyzer\TraitAnalyzer + && (!$functionlike_storage + || !isset($functionlike_storage->param_lookup[substr($var_id, 1)]))) + ) { + $codebase = $statements_analyzer->getCodebase(); + $codebase->analyzer->decrementMixedCount($statements_analyzer->getFilePath()); + } } IssueBuffer::remove( diff --git a/src/Psalm/Internal/Codebase/Analyzer.php b/src/Psalm/Internal/Codebase/Analyzer.php index 583074ca633..ae39a3e7281 100644 --- a/src/Psalm/Internal/Codebase/Analyzer.php +++ b/src/Psalm/Internal/Codebase/Analyzer.php @@ -1216,6 +1216,10 @@ public function decrementMixedCount(string $file_path): void return; } + if ($this->mixed_counts[$file_path][0] === 0) { + return; + } + --$this->mixed_counts[$file_path][0]; } @@ -1403,7 +1407,7 @@ public function getNonMixedStats(): string [$path_mixed_count, $path_nonmixed_count] = $this->mixed_counts[$file_path]; if ($path_mixed_count + $path_nonmixed_count) { - $stats .= number_format(100 * $path_nonmixed_count / ($path_mixed_count + $path_nonmixed_count), 0) + $stats .= number_format(100 * $path_nonmixed_count / ($path_mixed_count + $path_nonmixed_count), 3) . '% ' . $this->config->shortenFileName($file_path) . ' (' . $path_mixed_count . ' mixed)' . "\n"; }