diff --git a/tests/PHPStan/Rules/Comparison/DoWhileLoopConstantConditionRuleTest.php b/tests/PHPStan/Rules/Comparison/DoWhileLoopConstantConditionRuleTest.php index cbfdf67cad..f83f2cf1b0 100644 --- a/tests/PHPStan/Rules/Comparison/DoWhileLoopConstantConditionRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/DoWhileLoopConstantConditionRuleTest.php @@ -11,8 +11,6 @@ class DoWhileLoopConstantConditionRuleTest extends RuleTestCase { - private bool $treatPhpDocTypesAsCertain = true; - protected function getRule(): Rule { return new DoWhileLoopConstantConditionRule( @@ -21,20 +19,15 @@ protected function getRule(): Rule self::createReflectionProvider(), $this->getTypeSpecifier(), [], - $this->treatPhpDocTypesAsCertain, + $this->shouldTreatPhpDocTypesAsCertain(), ), - $this->treatPhpDocTypesAsCertain, + $this->shouldTreatPhpDocTypesAsCertain(), ), - $this->treatPhpDocTypesAsCertain, + $this->shouldTreatPhpDocTypesAsCertain(), true, ); } - protected function shouldTreatPhpDocTypesAsCertain(): bool - { - return $this->treatPhpDocTypesAsCertain; - } - public function testRule(): void { $this->analyse([__DIR__ . '/data/do-while-loop.php'], [ diff --git a/tests/PHPStan/Rules/Comparison/LogicalXorConstantConditionRuleTest.php b/tests/PHPStan/Rules/Comparison/LogicalXorConstantConditionRuleTest.php index f3ed1ef002..99e45cf088 100644 --- a/tests/PHPStan/Rules/Comparison/LogicalXorConstantConditionRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/LogicalXorConstantConditionRuleTest.php @@ -11,8 +11,6 @@ class LogicalXorConstantConditionRuleTest extends RuleTestCase { - private bool $treatPhpDocTypesAsCertain; - private bool $reportAlwaysTrueInLastCondition = false; protected function getRule(): TRule @@ -23,11 +21,11 @@ protected function getRule(): TRule self::createReflectionProvider(), $this->getTypeSpecifier(), [], - $this->treatPhpDocTypesAsCertain, + $this->shouldTreatPhpDocTypesAsCertain(), ), - $this->treatPhpDocTypesAsCertain, + $this->shouldTreatPhpDocTypesAsCertain(), ), - $this->treatPhpDocTypesAsCertain, + $this->shouldTreatPhpDocTypesAsCertain(), $this->reportAlwaysTrueInLastCondition, true, ); @@ -36,7 +34,6 @@ protected function getRule(): TRule public function testRule(): void { $tipText = 'Because the type is coming from a PHPDoc, you can turn off this check by setting treatPhpDocTypesAsCertain: false in your %configurationFile%.'; - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/logical-xor.php'], [ [ 'Left side of xor is always true.', diff --git a/tests/PHPStan/Rules/Comparison/WhileLoopAlwaysFalseConditionRuleTest.php b/tests/PHPStan/Rules/Comparison/WhileLoopAlwaysFalseConditionRuleTest.php index a41bc8158f..c434368b47 100644 --- a/tests/PHPStan/Rules/Comparison/WhileLoopAlwaysFalseConditionRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/WhileLoopAlwaysFalseConditionRuleTest.php @@ -11,8 +11,6 @@ class WhileLoopAlwaysFalseConditionRuleTest extends RuleTestCase { - private bool $treatPhpDocTypesAsCertain = true; - protected function getRule(): Rule { return new WhileLoopAlwaysFalseConditionRule( @@ -21,20 +19,15 @@ protected function getRule(): Rule self::createReflectionProvider(), $this->getTypeSpecifier(), [], - $this->treatPhpDocTypesAsCertain, + $this->shouldTreatPhpDocTypesAsCertain(), ), - $this->treatPhpDocTypesAsCertain, + $this->shouldTreatPhpDocTypesAsCertain(), ), - $this->treatPhpDocTypesAsCertain, + $this->shouldTreatPhpDocTypesAsCertain(), true, ); } - protected function shouldTreatPhpDocTypesAsCertain(): bool - { - return $this->treatPhpDocTypesAsCertain; - } - public function testRule(): void { $this->analyse([__DIR__ . '/data/while-loop-false.php'], [ diff --git a/tests/PHPStan/Rules/Comparison/WhileLoopAlwaysTrueConditionRuleTest.php b/tests/PHPStan/Rules/Comparison/WhileLoopAlwaysTrueConditionRuleTest.php index 7a1e99f5c1..45bcf32a83 100644 --- a/tests/PHPStan/Rules/Comparison/WhileLoopAlwaysTrueConditionRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/WhileLoopAlwaysTrueConditionRuleTest.php @@ -11,8 +11,6 @@ class WhileLoopAlwaysTrueConditionRuleTest extends RuleTestCase { - private bool $treatPhpDocTypesAsCertain = true; - protected function getRule(): Rule { return new WhileLoopAlwaysTrueConditionRule( @@ -21,20 +19,15 @@ protected function getRule(): Rule self::createReflectionProvider(), $this->getTypeSpecifier(), [], - $this->treatPhpDocTypesAsCertain, + $this->shouldTreatPhpDocTypesAsCertain(), ), - $this->treatPhpDocTypesAsCertain, + $this->shouldTreatPhpDocTypesAsCertain(), ), - $this->treatPhpDocTypesAsCertain, + $this->shouldTreatPhpDocTypesAsCertain(), true, ); } - protected function shouldTreatPhpDocTypesAsCertain(): bool - { - return $this->treatPhpDocTypesAsCertain; - } - public function testRule(): void { $this->analyse([__DIR__ . '/data/while-loop-true.php'], [ diff --git a/tests/PHPStan/Rules/Functions/ArrayValuesRuleTest.php b/tests/PHPStan/Rules/Functions/ArrayValuesRuleTest.php index face9ea8f5..1f3e273b16 100644 --- a/tests/PHPStan/Rules/Functions/ArrayValuesRuleTest.php +++ b/tests/PHPStan/Rules/Functions/ArrayValuesRuleTest.php @@ -12,13 +12,11 @@ class ArrayValuesRuleTest extends RuleTestCase { - private bool $treatPhpDocTypesAsCertain = true; - protected function getRule(): Rule { return new ArrayValuesRule( self::createReflectionProvider(), - $this->treatPhpDocTypesAsCertain, + $this->shouldTreatPhpDocTypesAsCertain(), true, ); } diff --git a/tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php b/tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php index 3c18294d1c..6ffb9013bc 100644 --- a/tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php +++ b/tests/PHPStan/Rules/Variables/NullCoalesceRuleTest.php @@ -16,23 +16,16 @@ class NullCoalesceRuleTest extends RuleTestCase { - private bool $treatPhpDocTypesAsCertain; - protected function getRule(): Rule { return new NullCoalesceRule(new IssetCheck( new PropertyDescriptor(), new PropertyReflectionFinder(), true, - $this->treatPhpDocTypesAsCertain, + $this->shouldTreatPhpDocTypesAsCertain(), )); } - protected function shouldTreatPhpDocTypesAsCertain(): bool - { - return $this->treatPhpDocTypesAsCertain; - } - public function shouldNarrowMethodScopeFromConstructor(): bool { return true; @@ -40,7 +33,6 @@ public function shouldNarrowMethodScopeFromConstructor(): bool public function testCoalesceRule(): void { - $this->treatPhpDocTypesAsCertain = true; $errors = [ [ 'Property CoalesceRule\FooCoalesce::$string (string) on left side of ?? is not nullable.', @@ -146,7 +138,6 @@ public function testCoalesceRule(): void public function testCoalesceAssignRule(): void { - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/null-coalesce-assign.php'], [ [ 'Property CoalesceAssignRule\FooCoalesce::$string (string) on left side of ??= is not nullable.', @@ -209,13 +200,11 @@ public function testCoalesceAssignRule(): void public function testNullsafe(): void { - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/null-coalesce-nullsafe.php'], []); } public function testVariableCertaintyInNullCoalesce(): void { - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/variable-certainty-null.php'], [ [ 'Variable $scalar on left side of ?? always exists and is not nullable.', @@ -234,7 +223,6 @@ public function testVariableCertaintyInNullCoalesce(): void public function testVariableCertaintyInNullCoalesceAssign(): void { - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/variable-certainty-null-assign.php'], [ [ 'Variable $scalar on left side of ??= always exists and is not nullable.', @@ -253,7 +241,6 @@ public function testVariableCertaintyInNullCoalesceAssign(): void public function testNullCoalesceInGlobalScope(): void { - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/null-coalesce-global-scope.php'], [ [ 'Variable $bar on left side of ?? always exists and is not nullable.', @@ -264,15 +251,12 @@ public function testNullCoalesceInGlobalScope(): void public function testBug5933(): void { - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/bug-5933.php'], []); } #[RequiresPhp('>= 8.0')] public function testBug7109(): void { - $this->treatPhpDocTypesAsCertain = true; - $this->analyse([__DIR__ . '/../Properties/data/bug-7109.php'], [ [ 'Using nullsafe property access "?->aaa" on left side of ?? is unnecessary. Use -> instead.', @@ -299,8 +283,6 @@ public function testBug7109(): void public function testBug7190(): void { - $this->treatPhpDocTypesAsCertain = true; - $this->analyse([__DIR__ . '/../Properties/data/bug-7190.php'], [ [ 'Offset int on array on left side of ?? always exists and is not nullable.', @@ -311,8 +293,6 @@ public function testBug7190(): void public function testBug7318(): void { - $this->treatPhpDocTypesAsCertain = true; - $this->analyse([__DIR__ . '/../Properties/data/bug-7318.php'], [ [ "Offset 'unique' on array{unique: bool} on left side of ?? always exists and is not nullable.", @@ -323,50 +303,37 @@ public function testBug7318(): void public function testBug7968(): void { - $this->treatPhpDocTypesAsCertain = true; - $this->analyse([__DIR__ . '/data/bug-7968.php'], []); } public function testBug8084(): void { - $this->treatPhpDocTypesAsCertain = true; - $this->analyse([__DIR__ . '/data/bug-8084.php'], []); } public function testBug10577(): void { - $this->treatPhpDocTypesAsCertain = true; - $this->analyse([__DIR__ . '/data/bug-10577.php'], []); } public function testBug11708(): void { - $this->treatPhpDocTypesAsCertain = true; - $this->analyse([__DIR__ . '/data/bug-11708.php'], []); } public function testBug10610(): void { - $this->treatPhpDocTypesAsCertain = true; - $this->analyse([__DIR__ . '/data/bug-10610.php'], []); } #[RequiresPhp('>= 8.4')] public function testBug12553(): void { - $this->treatPhpDocTypesAsCertain = true; $this->analyse([__DIR__ . '/data/bug-12553.php'], []); } public function testIssetAfterRememberedConstructor(): void { - $this->treatPhpDocTypesAsCertain = true; - $this->analyse([__DIR__ . '/data/isset-after-remembered-constructor.php'], [ [ 'Property IssetOrCoalesceOnNonNullableInitializedProperty\User::$string on left side of ?? is not nullable nor uninitialized.',