Skip to content

Commit 3bdadcf

Browse files
committed
ignore also bool phpdoc
1 parent b043e55 commit 3bdadcf

File tree

4 files changed

+18
-34
lines changed

4 files changed

+18
-34
lines changed

src/Rules/TooWideTypehints/TooWideTypeCheck.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,13 @@ public function checkFunctionReturnType(
176176
if (count($returnStatements) === 0) {
177177
return [];
178178
}
179-
if (count($returnStatements) === 1 && $nativeFunctionReturnType->isBoolean()->yes()) {
179+
if (
180+
count($returnStatements) === 1
181+
&& (
182+
$nativeFunctionReturnType->isBoolean()->yes()
183+
|| $phpDocFunctionReturnType->isBoolean()->yes()
184+
)
185+
) {
180186
return [];
181187
}
182188

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,23 +1099,15 @@ public function testBug8376(): void
10991099
public function testAssertDocblock(): void
11001100
{
11011101
$errors = $this->runAnalyse(__DIR__ . '/nsrt/assert-docblock.php');
1102-
$this->assertCount(8, $errors);
1103-
$this->assertSame('Function AssertDocblock\validateStringArrayIfTrue() never returns false so the return type can be changed to true.', $errors[0]->getMessage());
1104-
$this->assertSame(17, $errors[0]->getLine());
1105-
$this->assertSame('Function AssertDocblock\validateStringArrayIfFalse() never returns true so the return type can be changed to false.', $errors[1]->getMessage());
1106-
$this->assertSame(25, $errors[1]->getLine());
1107-
$this->assertSame('Function AssertDocblock\validateStringOrIntArray() never returns true so the return type can be changed to false.', $errors[2]->getMessage());
1108-
$this->assertSame(34, $errors[2]->getLine());
1109-
$this->assertSame('Function AssertDocblock\validateStringOrNonEmptyIntArray() never returns true so the return type can be changed to false.', $errors[3]->getMessage());
1110-
$this->assertSame(44, $errors[3]->getLine());
1111-
$this->assertSame('Call to method AssertDocblock\A::testInt() with string will always evaluate to false.', $errors[4]->getMessage());
1112-
$this->assertSame(218, $errors[4]->getLine());
1113-
$this->assertSame('Call to method AssertDocblock\A::testNotInt() with string will always evaluate to true.', $errors[5]->getMessage());
1114-
$this->assertSame(224, $errors[5]->getLine());
1115-
$this->assertSame('Call to method AssertDocblock\A::testInt() with int will always evaluate to true.', $errors[6]->getMessage());
1116-
$this->assertSame(232, $errors[6]->getLine());
1117-
$this->assertSame('Call to method AssertDocblock\A::testNotInt() with int will always evaluate to false.', $errors[7]->getMessage());
1118-
$this->assertSame(238, $errors[7]->getLine());
1102+
$this->assertCount(4, $errors);
1103+
$this->assertSame('Call to method AssertDocblock\A::testInt() with string will always evaluate to false.', $errors[0]->getMessage());
1104+
$this->assertSame(218, $errors[0]->getLine());
1105+
$this->assertSame('Call to method AssertDocblock\A::testNotInt() with string will always evaluate to true.', $errors[1]->getMessage());
1106+
$this->assertSame(224, $errors[1]->getLine());
1107+
$this->assertSame('Call to method AssertDocblock\A::testInt() with int will always evaluate to true.', $errors[2]->getMessage());
1108+
$this->assertSame(232, $errors[2]->getLine());
1109+
$this->assertSame('Call to method AssertDocblock\A::testNotInt() with int will always evaluate to false.', $errors[3]->getMessage());
1110+
$this->assertSame(238, $errors[3]->getLine());
11191111
}
11201112

11211113
#[RequiresPhp('>= 8.0')]

tests/PHPStan/Rules/TooWideTypehints/TooWideFunctionReturnTypehintRuleTest.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,7 @@ public function testBug13384cPhp82(): void
7777
{
7878
$this->reportTooWideBool = true;
7979
$this->reportNestedTooWideType = true;
80-
$this->analyse([__DIR__ . '/data/bug-13384c.php'], [
81-
[
82-
'Function Bug13384c\doFooPhpdoc2() never returns true so the return type can be changed to false.',
83-
100,
84-
],
85-
]);
80+
$this->analyse([__DIR__ . '/data/bug-13384c.php'], []);
8681
}
8782

8883
#[RequiresPhp('< 8.2')]

tests/PHPStan/Rules/TooWideTypehints/TooWideMethodReturnTypehintRuleTest.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,7 @@ public function testBug13384c(): void
230230
{
231231
$this->reportTooWideBool = true;
232232
$this->reportNestedTooWideType = true;
233-
$this->analyse([__DIR__ . '/data/bug-13384c.php'], [
234-
[
235-
'Method Bug13384c\Bug13384c::doBarPhpdoc() never returns false so the return type can be changed to true.',
236-
55,
237-
],
238-
[
239-
'Method Bug13384c\Bug13384Static::doBarPhpdoc() never returns false so the return type can be changed to true.',
240-
84,
241-
],
242-
]);
233+
$this->analyse([__DIR__ . '/data/bug-13384c.php'], []);
243234
}
244235

245236
#[RequiresPhp('< 8.2')]

0 commit comments

Comments
 (0)