From 565fb0f6da9cdc58e8686598015561a848693972 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Mon, 9 Jan 2023 14:06:03 +0100 Subject: [PATCH] Bleeding edge - always report always true conditions, except for last elseif and match arm --- conf/bleedingEdge.neon | 1 + conf/config.neon | 10 ++++--- .../Analyser/AnalyserIntegrationTest.php | 26 ++++++++++++++----- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/conf/bleedingEdge.neon b/conf/bleedingEdge.neon index 43856382a7..f58bb57f85 100644 --- a/conf/bleedingEdge.neon +++ b/conf/bleedingEdge.neon @@ -25,3 +25,4 @@ parameters: unescapeStrings: true duplicateStubs: true invarianceComposition: true + alwaysTrueAlwaysReported: true diff --git a/conf/config.neon b/conf/config.neon index d89d88c0da..44081aff60 100644 --- a/conf/config.neon +++ b/conf/config.neon @@ -55,13 +55,14 @@ parameters: unescapeStrings: false duplicateStubs: false invarianceComposition: false + alwaysTrueAlwaysReported: false fileExtensions: - php checkAdvancedIsset: false - checkAlwaysTrueCheckTypeFunctionCall: false - checkAlwaysTrueInstanceof: false - checkAlwaysTrueStrictComparison: false - checkAlwaysTrueLooseComparison: false + checkAlwaysTrueCheckTypeFunctionCall: %featureToggles.alwaysTrueAlwaysReported% + checkAlwaysTrueInstanceof: %featureToggles.alwaysTrueAlwaysReported% + checkAlwaysTrueStrictComparison: %featureToggles.alwaysTrueAlwaysReported% + checkAlwaysTrueLooseComparison: %featureToggles.alwaysTrueAlwaysReported% checkClassCaseSensitivity: false checkExplicitMixed: false checkImplicitMixed: false @@ -275,6 +276,7 @@ parametersSchema: unescapeStrings: bool() duplicateStubs: bool() invarianceComposition: bool() + alwaysTrueAlwaysReported: bool() ]) fileExtensions: listOf(string()) checkAdvancedIsset: bool() diff --git a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php index 029f43620e..3f9e5ad2c2 100644 --- a/tests/PHPStan/Analyser/AnalyserIntegrationTest.php +++ b/tests/PHPStan/Analyser/AnalyserIntegrationTest.php @@ -617,7 +617,9 @@ public function testBug6896(): void public function testBug6940(): void { $errors = $this->runAnalyse(__DIR__ . '/data/bug-6940.php'); - $this->assertNoErrors($errors); + $this->assertCount(1, $errors); + $this->assertSame('Loose comparison using == between array{} and array{} will always evaluate to true.', $errors[0]->getMessage()); + $this->assertSame(12, $errors[0]->getLine()); } public function testBug1447(): void @@ -881,13 +883,16 @@ public function testBug7554(): void public function testBug7637(): void { $errors = $this->runAnalyse(__DIR__ . '/data/bug-7637.php'); - $this->assertCount(2, $errors); + $this->assertCount(3, $errors); $this->assertSame('Method Bug7637\HelloWorld::getProperty() has invalid return type Bug7637\rex_backend_login.', $errors[0]->getMessage()); $this->assertSame(54, $errors[0]->getLine()); $this->assertSame('Method Bug7637\HelloWorld::getProperty() has invalid return type Bug7637\rex_timer.', $errors[1]->getMessage()); $this->assertSame(54, $errors[1]->getLine()); + + $this->assertSame('Call to function is_string() with string will always evaluate to true.', $errors[2]->getMessage()); + $this->assertSame(57, $errors[2]->getLine()); } public function testBug7737(): void @@ -1022,11 +1027,15 @@ public function testBug8376(): void public function testAssertDocblock(): void { $errors = $this->runAnalyse(__DIR__ . '/data/assert-docblock.php'); - $this->assertCount(2, $errors); + $this->assertCount(4, $errors); $this->assertSame('Call to method AssertDocblock\A::testInt() with string will always evaluate to false.', $errors[0]->getMessage()); $this->assertSame(218, $errors[0]->getLine()); - $this->assertSame('Call to method AssertDocblock\A::testNotInt() with int will always evaluate to false.', $errors[1]->getMessage()); - $this->assertSame(238, $errors[1]->getLine()); + $this->assertSame('Call to method AssertDocblock\A::testNotInt() with string will always evaluate to true.', $errors[1]->getMessage()); + $this->assertSame(224, $errors[1]->getLine()); + $this->assertSame('Call to method AssertDocblock\A::testInt() with int will always evaluate to true.', $errors[2]->getMessage()); + $this->assertSame(232, $errors[2]->getLine()); + $this->assertSame('Call to method AssertDocblock\A::testNotInt() with int will always evaluate to false.', $errors[3]->getMessage()); + $this->assertSame(238, $errors[3]->getLine()); } public function testBug8147(): void @@ -1101,7 +1110,12 @@ public static function getAdditionalConfigFiles(): array public function testBug8004(): void { $errors = $this->runAnalyse(__DIR__ . '/data/bug-8004.php'); - $this->assertNoErrors($errors); + $this->assertCount(2, $errors); + $this->assertSame('Strict comparison using !== between null and DateTimeInterface|string will always evaluate to true.', $errors[0]->getMessage()); + $this->assertSame(49, $errors[0]->getLine()); + + $this->assertSame('Strict comparison using !== between null and DateTimeInterface|string will always evaluate to true.', $errors[1]->getMessage()); + $this->assertSame(59, $errors[1]->getLine()); } public function testSkipCheckNoGenericClasses(): void