mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Remove more unused code from LoopAnalyzer
This commit is contained in:
parent
5575fa1e32
commit
2eca28c912
@ -157,6 +157,9 @@ class LoopAnalyzer
|
||||
|
||||
$original_mixed_counts = $analyzer->getMixedCountsForFile($statements_analyzer->getFilePath());
|
||||
|
||||
// record all the vars that existed before we did the first pass through the loop
|
||||
$pre_loop_context = clone $loop_context;
|
||||
|
||||
IssueBuffer::startRecording();
|
||||
|
||||
if (!$is_do) {
|
||||
@ -172,9 +175,6 @@ class LoopAnalyzer
|
||||
}
|
||||
}
|
||||
|
||||
// record all the vars that existed before we did the first pass through the loop
|
||||
$pre_loop_context = clone $loop_context;
|
||||
|
||||
$continue_context = clone $loop_context;
|
||||
|
||||
foreach ($continue_context->vars_in_scope as $context_var_id => $context_type) {
|
||||
@ -597,18 +597,6 @@ class LoopAnalyzer
|
||||
|
||||
$loop_context->inside_conditional = true;
|
||||
|
||||
$suppressed_issues = $statements_analyzer->getSuppressedIssues();
|
||||
|
||||
if (!in_array('RedundantCondition', $suppressed_issues, true)) {
|
||||
$statements_analyzer->addSuppressedIssues(['RedundantCondition']);
|
||||
}
|
||||
if (!in_array('RedundantConditionGivenDocblockType', $suppressed_issues, true)) {
|
||||
$statements_analyzer->addSuppressedIssues(['RedundantConditionGivenDocblockType']);
|
||||
}
|
||||
if (!in_array('TypeDoesNotContainType', $suppressed_issues, true)) {
|
||||
$statements_analyzer->addSuppressedIssues(['TypeDoesNotContainType']);
|
||||
}
|
||||
|
||||
if (ExpressionAnalyzer::analyze($statements_analyzer, $pre_condition, $loop_context) === false) {
|
||||
$loop_context->inside_conditional = $was_inside_conditional;
|
||||
|
||||
@ -631,7 +619,8 @@ class LoopAnalyzer
|
||||
$reconcilable_while_types = Algebra::getTruthsFromFormula(
|
||||
$loop_context->clauses,
|
||||
spl_object_id($pre_condition),
|
||||
$new_referenced_var_ids
|
||||
$new_referenced_var_ids,
|
||||
$active_while_types
|
||||
);
|
||||
|
||||
$changed_var_ids = [];
|
||||
@ -653,16 +642,6 @@ class LoopAnalyzer
|
||||
$loop_context->vars_in_scope = $pre_condition_vars_in_scope_reconciled;
|
||||
}
|
||||
|
||||
if (!in_array('RedundantCondition', $suppressed_issues, true)) {
|
||||
$statements_analyzer->removeSuppressedIssues(['RedundantCondition']);
|
||||
}
|
||||
if (!in_array('RedundantConditionGivenDocblockType', $suppressed_issues, true)) {
|
||||
$statements_analyzer->removeSuppressedIssues(['RedundantConditionGivenDocblockType']);
|
||||
}
|
||||
if (!in_array('TypeDoesNotContainType', $suppressed_issues, true)) {
|
||||
$statements_analyzer->removeSuppressedIssues(['TypeDoesNotContainType']);
|
||||
}
|
||||
|
||||
if ($is_do) {
|
||||
return [];
|
||||
}
|
||||
|
@ -497,97 +497,6 @@ class WhileTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'propertyAssertionInsideWhile' => [
|
||||
'code' => '<?php
|
||||
class Foo {
|
||||
public array $a = [];
|
||||
public array $b = [];
|
||||
public array $c = [];
|
||||
|
||||
public function one(): bool {
|
||||
$has_changes = false;
|
||||
|
||||
while ($this->a) {
|
||||
$has_changes = true;
|
||||
$this->alter();
|
||||
}
|
||||
|
||||
return $has_changes;
|
||||
}
|
||||
|
||||
public function two(): bool {
|
||||
$has_changes = false;
|
||||
|
||||
while ($this->a || $this->b) {
|
||||
$has_changes = true;
|
||||
$this->alter();
|
||||
}
|
||||
|
||||
return $has_changes;
|
||||
}
|
||||
|
||||
public function three(): bool {
|
||||
$has_changes = false;
|
||||
|
||||
while ($this->a || $this->b || $this->c) {
|
||||
$has_changes = true;
|
||||
$this->alter();
|
||||
}
|
||||
|
||||
return $has_changes;
|
||||
}
|
||||
|
||||
public function four(): bool {
|
||||
$has_changes = false;
|
||||
|
||||
while (($this->a && $this->b) || $this->c) {
|
||||
$has_changes = true;
|
||||
$this->alter();
|
||||
}
|
||||
|
||||
return $has_changes;
|
||||
}
|
||||
|
||||
public function alter() : void {
|
||||
if (rand(0, 1)) {
|
||||
array_pop($this->a);
|
||||
} elseif (rand(0, 1)) {
|
||||
array_pop($this->a);
|
||||
} else {
|
||||
array_pop($this->c);
|
||||
}
|
||||
}
|
||||
}'
|
||||
],
|
||||
'propertyAssertionInsideWhileNested' => [
|
||||
'code' => '<?php
|
||||
class Foo {
|
||||
public array $a = [];
|
||||
public array $b = [];
|
||||
public array $c = [];
|
||||
|
||||
public function five(): bool {
|
||||
$has_changes = false;
|
||||
|
||||
while ($this->a || ($this->b && $this->c)) {
|
||||
$has_changes = true;
|
||||
$this->alter();
|
||||
}
|
||||
|
||||
return $has_changes;
|
||||
}
|
||||
|
||||
public function alter() : void {
|
||||
if (rand(0, 1)) {
|
||||
array_pop($this->a);
|
||||
} elseif (rand(0, 1)) {
|
||||
array_pop($this->a);
|
||||
} else {
|
||||
array_pop($this->c);
|
||||
}
|
||||
}
|
||||
}'
|
||||
],
|
||||
'ifNestedInsideLoop' => [
|
||||
'code' => '<?php
|
||||
function analyse(): int {
|
||||
|
@ -290,6 +290,211 @@ class PropertyTypeTest extends TestCase
|
||||
$this->analyzeFile('somefile.php', new Context());
|
||||
}
|
||||
|
||||
public function testAssertionInsideWhileOne(): void
|
||||
{
|
||||
Config::getInstance()->remember_property_assignments_after_call = false;
|
||||
|
||||
$this->addFile(
|
||||
'somefile.php',
|
||||
'<?php
|
||||
class Foo {
|
||||
public array $a = [];
|
||||
public array $b = [];
|
||||
public array $c = [];
|
||||
|
||||
public function one(): bool {
|
||||
$has_changes = false;
|
||||
|
||||
while ($this->a) {
|
||||
$has_changes = true;
|
||||
$this->alter();
|
||||
}
|
||||
|
||||
return $has_changes;
|
||||
}
|
||||
|
||||
public function alter() : void {
|
||||
if (rand(0, 1)) {
|
||||
array_pop($this->a);
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
array_pop($this->b);
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
array_pop($this->c);
|
||||
}
|
||||
}
|
||||
}'
|
||||
);
|
||||
|
||||
$this->analyzeFile('somefile.php', new Context());
|
||||
}
|
||||
|
||||
public function testAssertionInsideWhileTwo(): void
|
||||
{
|
||||
Config::getInstance()->remember_property_assignments_after_call = false;
|
||||
|
||||
$this->addFile(
|
||||
'somefile.php',
|
||||
'<?php
|
||||
class Foo {
|
||||
public array $a = [];
|
||||
public array $b = [];
|
||||
|
||||
public function two(): bool {
|
||||
$has_changes = false;
|
||||
|
||||
while ($this->a || $this->b) {
|
||||
$has_changes = true;
|
||||
$this->alter();
|
||||
}
|
||||
|
||||
return $has_changes;
|
||||
}
|
||||
|
||||
public function alter() : void {
|
||||
if (rand(0, 1)) {
|
||||
array_pop($this->a);
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
array_pop($this->b);
|
||||
}
|
||||
}
|
||||
}'
|
||||
);
|
||||
|
||||
$this->analyzeFile('somefile.php', new Context());
|
||||
}
|
||||
|
||||
public function testAssertionInsideWhileThree(): void
|
||||
{
|
||||
Config::getInstance()->remember_property_assignments_after_call = false;
|
||||
|
||||
$this->addFile(
|
||||
'somefile.php',
|
||||
'<?php
|
||||
class Foo {
|
||||
public array $a = [];
|
||||
public array $b = [];
|
||||
public array $c = [];
|
||||
|
||||
public function three(): bool {
|
||||
$has_changes = false;
|
||||
|
||||
while ($this->a || $this->b || $this->c) {
|
||||
$has_changes = true;
|
||||
$this->alter();
|
||||
}
|
||||
|
||||
return $has_changes;
|
||||
}
|
||||
|
||||
public function alter() : void {
|
||||
if (rand(0, 1)) {
|
||||
array_pop($this->a);
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
array_pop($this->b);
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
array_pop($this->c);
|
||||
}
|
||||
}
|
||||
}'
|
||||
);
|
||||
|
||||
$this->analyzeFile('somefile.php', new Context());
|
||||
}
|
||||
|
||||
public function testAssertionInsideWhileFour(): void
|
||||
{
|
||||
Config::getInstance()->remember_property_assignments_after_call = false;
|
||||
|
||||
$this->addFile(
|
||||
'somefile.php',
|
||||
'<?php
|
||||
class Foo {
|
||||
public array $a = [];
|
||||
public array $b = [];
|
||||
public array $c = [];
|
||||
|
||||
public function four(): bool {
|
||||
$has_changes = false;
|
||||
|
||||
while (($this->a && $this->b) || $this->c) {
|
||||
$has_changes = true;
|
||||
$this->alter();
|
||||
}
|
||||
|
||||
return $has_changes;
|
||||
}
|
||||
|
||||
public function alter() : void {
|
||||
if (rand(0, 1)) {
|
||||
array_pop($this->a);
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
array_pop($this->b);
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
array_pop($this->c);
|
||||
}
|
||||
}
|
||||
}'
|
||||
);
|
||||
|
||||
$this->analyzeFile('somefile.php', new Context());
|
||||
}
|
||||
|
||||
public function testAssertionInsideWhileFive(): void
|
||||
{
|
||||
Config::getInstance()->remember_property_assignments_after_call = false;
|
||||
|
||||
$this->addFile(
|
||||
'somefile.php',
|
||||
'<?php
|
||||
class Foo {
|
||||
public array $a = [];
|
||||
public array $b = [];
|
||||
public array $c = [];
|
||||
|
||||
public function five(): bool {
|
||||
$has_changes = false;
|
||||
|
||||
while ($this->a || ($this->b && $this->c)) {
|
||||
$has_changes = true;
|
||||
$this->alter();
|
||||
}
|
||||
|
||||
return $has_changes;
|
||||
}
|
||||
|
||||
public function alter() : void {
|
||||
if (rand(0, 1)) {
|
||||
array_pop($this->a);
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
array_pop($this->b);
|
||||
}
|
||||
|
||||
if (rand(0, 1)) {
|
||||
array_pop($this->c);
|
||||
}
|
||||
}
|
||||
}'
|
||||
);
|
||||
|
||||
$this->analyzeFile('somefile.php', new Context());
|
||||
}
|
||||
|
||||
public function testUniversalObjectCrates(): void
|
||||
{
|
||||
Config::getInstance()->addUniversalObjectCrate(DateTime::class);
|
||||
|
Loading…
x
Reference in New Issue
Block a user