mirror of
https://github.com/danog/psalm.git
synced 2024-12-04 18:48:03 +01:00
Fix #3660 - ensure mixed percentage for file never drops below 0
This commit is contained in:
parent
1b19670c39
commit
a4479761a7
@ -312,12 +312,21 @@ class IfAnalyzer
|
||||
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(
|
||||
|
@ -1216,6 +1216,10 @@ class Analyzer
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->mixed_counts[$file_path][0] === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
--$this->mixed_counts[$file_path][0];
|
||||
}
|
||||
|
||||
@ -1403,7 +1407,7 @@ class Analyzer
|
||||
[$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";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user