Skip to content

Commit

Permalink
Bleeding edge - always report always true conditions, except for last…
Browse files Browse the repository at this point in the history
… elseif and match arm
  • Loading branch information
ondrejmirtes committed Jan 9, 2023
1 parent 4968ec6 commit 565fb0f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions conf/bleedingEdge.neon
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ parameters:
unescapeStrings: true
duplicateStubs: true
invarianceComposition: true
alwaysTrueAlwaysReported: true
10 changes: 6 additions & 4 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -275,6 +276,7 @@ parametersSchema:
unescapeStrings: bool()
duplicateStubs: bool()
invarianceComposition: bool()
alwaysTrueAlwaysReported: bool()
])
fileExtensions: listOf(string())
checkAdvancedIsset: bool()
Expand Down
26 changes: 20 additions & 6 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 565fb0f

Please sign in to comment.