Skip to content

Commit 565fb0f

Browse files
committed
Bleeding edge - always report always true conditions, except for last elseif and match arm
1 parent 4968ec6 commit 565fb0f

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

conf/bleedingEdge.neon

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ parameters:
2525
unescapeStrings: true
2626
duplicateStubs: true
2727
invarianceComposition: true
28+
alwaysTrueAlwaysReported: true

conf/config.neon

+6-4
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ parameters:
5555
unescapeStrings: false
5656
duplicateStubs: false
5757
invarianceComposition: false
58+
alwaysTrueAlwaysReported: false
5859
fileExtensions:
5960
- php
6061
checkAdvancedIsset: false
61-
checkAlwaysTrueCheckTypeFunctionCall: false
62-
checkAlwaysTrueInstanceof: false
63-
checkAlwaysTrueStrictComparison: false
64-
checkAlwaysTrueLooseComparison: false
62+
checkAlwaysTrueCheckTypeFunctionCall: %featureToggles.alwaysTrueAlwaysReported%
63+
checkAlwaysTrueInstanceof: %featureToggles.alwaysTrueAlwaysReported%
64+
checkAlwaysTrueStrictComparison: %featureToggles.alwaysTrueAlwaysReported%
65+
checkAlwaysTrueLooseComparison: %featureToggles.alwaysTrueAlwaysReported%
6566
checkClassCaseSensitivity: false
6667
checkExplicitMixed: false
6768
checkImplicitMixed: false
@@ -275,6 +276,7 @@ parametersSchema:
275276
unescapeStrings: bool()
276277
duplicateStubs: bool()
277278
invarianceComposition: bool()
279+
alwaysTrueAlwaysReported: bool()
278280
])
279281
fileExtensions: listOf(string())
280282
checkAdvancedIsset: bool()

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

+20-6
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,9 @@ public function testBug6896(): void
617617
public function testBug6940(): void
618618
{
619619
$errors = $this->runAnalyse(__DIR__ . '/data/bug-6940.php');
620-
$this->assertNoErrors($errors);
620+
$this->assertCount(1, $errors);
621+
$this->assertSame('Loose comparison using == between array{} and array{} will always evaluate to true.', $errors[0]->getMessage());
622+
$this->assertSame(12, $errors[0]->getLine());
621623
}
622624

623625
public function testBug1447(): void
@@ -881,13 +883,16 @@ public function testBug7554(): void
881883
public function testBug7637(): void
882884
{
883885
$errors = $this->runAnalyse(__DIR__ . '/data/bug-7637.php');
884-
$this->assertCount(2, $errors);
886+
$this->assertCount(3, $errors);
885887

886888
$this->assertSame('Method Bug7637\HelloWorld::getProperty() has invalid return type Bug7637\rex_backend_login.', $errors[0]->getMessage());
887889
$this->assertSame(54, $errors[0]->getLine());
888890

889891
$this->assertSame('Method Bug7637\HelloWorld::getProperty() has invalid return type Bug7637\rex_timer.', $errors[1]->getMessage());
890892
$this->assertSame(54, $errors[1]->getLine());
893+
894+
$this->assertSame('Call to function is_string() with string will always evaluate to true.', $errors[2]->getMessage());
895+
$this->assertSame(57, $errors[2]->getLine());
891896
}
892897

893898
public function testBug7737(): void
@@ -1022,11 +1027,15 @@ public function testBug8376(): void
10221027
public function testAssertDocblock(): void
10231028
{
10241029
$errors = $this->runAnalyse(__DIR__ . '/data/assert-docblock.php');
1025-
$this->assertCount(2, $errors);
1030+
$this->assertCount(4, $errors);
10261031
$this->assertSame('Call to method AssertDocblock\A::testInt() with string will always evaluate to false.', $errors[0]->getMessage());
10271032
$this->assertSame(218, $errors[0]->getLine());
1028-
$this->assertSame('Call to method AssertDocblock\A::testNotInt() with int will always evaluate to false.', $errors[1]->getMessage());
1029-
$this->assertSame(238, $errors[1]->getLine());
1033+
$this->assertSame('Call to method AssertDocblock\A::testNotInt() with string will always evaluate to true.', $errors[1]->getMessage());
1034+
$this->assertSame(224, $errors[1]->getLine());
1035+
$this->assertSame('Call to method AssertDocblock\A::testInt() with int will always evaluate to true.', $errors[2]->getMessage());
1036+
$this->assertSame(232, $errors[2]->getLine());
1037+
$this->assertSame('Call to method AssertDocblock\A::testNotInt() with int will always evaluate to false.', $errors[3]->getMessage());
1038+
$this->assertSame(238, $errors[3]->getLine());
10301039
}
10311040

10321041
public function testBug8147(): void
@@ -1101,7 +1110,12 @@ public static function getAdditionalConfigFiles(): array
11011110
public function testBug8004(): void
11021111
{
11031112
$errors = $this->runAnalyse(__DIR__ . '/data/bug-8004.php');
1104-
$this->assertNoErrors($errors);
1113+
$this->assertCount(2, $errors);
1114+
$this->assertSame('Strict comparison using !== between null and DateTimeInterface|string will always evaluate to true.', $errors[0]->getMessage());
1115+
$this->assertSame(49, $errors[0]->getLine());
1116+
1117+
$this->assertSame('Strict comparison using !== between null and DateTimeInterface|string will always evaluate to true.', $errors[1]->getMessage());
1118+
$this->assertSame(59, $errors[1]->getLine());
11051119
}
11061120

11071121
public function testSkipCheckNoGenericClasses(): void

0 commit comments

Comments
 (0)