Skip to content

Commit 25ea487

Browse files
committed
Fix too wide bool in trivial methods
1 parent bdc429c commit 25ea487

File tree

3 files changed

+3
-28
lines changed

3 files changed

+3
-28
lines changed

src/Rules/TooWideTypehints/TooWideTypeCheck.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ public function checkFunctionReturnType(
176176
if (count($returnStatements) === 0) {
177177
return [];
178178
}
179+
if (count($returnStatements) === 1 && $nativeFunctionReturnType->isBoolean()->yes()) {
180+
return [];
181+
}
179182

180183
$returnTypes = [];
181184
foreach ($returnStatements as $returnStatement) {

tests/PHPStan/Rules/TooWideTypehints/TooWideFunctionReturnTypehintRuleTest.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,6 @@ public function testBug13384cPhp82(): void
7878
$this->reportTooWideBool = true;
7979
$this->reportNestedTooWideType = true;
8080
$this->analyse([__DIR__ . '/data/bug-13384c.php'], [
81-
[
82-
'Function Bug13384c\doFoo() never returns true so the return type can be changed to false.',
83-
5,
84-
],
85-
[
86-
'Function Bug13384c\doFoo2() never returns false so the return type can be changed to true.',
87-
9,
88-
],
89-
[
90-
'Function Bug13384c\doFooPhpdoc() never returns false so the return type can be changed to true.',
91-
93,
92-
],
9381
[
9482
'Function Bug13384c\doFooPhpdoc2() never returns true so the return type can be changed to false.',
9583
100,

tests/PHPStan/Rules/TooWideTypehints/TooWideMethodReturnTypehintRuleTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -231,26 +231,10 @@ public function testBug13384c(): void
231231
$this->reportTooWideBool = true;
232232
$this->reportNestedTooWideType = true;
233233
$this->analyse([__DIR__ . '/data/bug-13384c.php'], [
234-
[
235-
'Method Bug13384c\Bug13384c::doBar() never returns true so the return type can be changed to false.',
236-
33,
237-
],
238-
[
239-
'Method Bug13384c\Bug13384c::doBar2() never returns false so the return type can be changed to true.',
240-
37,
241-
],
242234
[
243235
'Method Bug13384c\Bug13384c::doBarPhpdoc() never returns false so the return type can be changed to true.',
244236
55,
245237
],
246-
[
247-
'Method Bug13384c\Bug13384Static::doBar() never returns true so the return type can be changed to false.',
248-
62,
249-
],
250-
[
251-
'Method Bug13384c\Bug13384Static::doBar2() never returns false so the return type can be changed to true.',
252-
66,
253-
],
254238
[
255239
'Method Bug13384c\Bug13384Static::doBarPhpdoc() never returns false so the return type can be changed to true.',
256240
84,

0 commit comments

Comments
 (0)