mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-22 18:54:39 +01:00
fix SimplifyIfReturnBoolRector
This commit is contained in:
parent
a8a1198aa6
commit
eb796af9fd
@ -79,6 +79,10 @@ CODE_SAMPLE
|
||||
return true;
|
||||
}
|
||||
|
||||
if (count($ifNode->elseifs) > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$ifInnerNode = $ifNode->stmts[0];
|
||||
if (! $ifInnerNode instanceof Return_) {
|
||||
return true;
|
||||
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
if (is_null($value)) {
|
||||
return false;
|
||||
} elseif (is_string($value) && trim($value) === '') {
|
||||
return false;
|
||||
} elseif ((is_array($value) || $value instanceof Countable) && count($value) < 1) {
|
||||
return false;
|
||||
} elseif ($value instanceof File) {
|
||||
return (string) $value->getPath() !== '';
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
if (is_null($value)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
@ -27,6 +27,7 @@ final class SimplifyIfReturnBoolRectorTest extends AbstractRectorTestCase
|
||||
yield [__DIR__ . '/Wrong/wrong5.php.inc', __DIR__ . '/Correct/correct5.php.inc'];
|
||||
yield [__DIR__ . '/Wrong/wrong6.php.inc', __DIR__ . '/Correct/correct6.php.inc'];
|
||||
yield [__DIR__ . '/Wrong/wrong7.php.inc', __DIR__ . '/Correct/correct7.php.inc'];
|
||||
yield [__DIR__ . '/Wrong/wrong8.php.inc', __DIR__ . '/Correct/correct8.php.inc'];
|
||||
}
|
||||
|
||||
protected function provideConfig(): string
|
||||
|
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
if (is_null($value)) {
|
||||
return false;
|
||||
} elseif (is_string($value) && trim($value) === '') {
|
||||
return false;
|
||||
} elseif ((is_array($value) || $value instanceof Countable) && count($value) < 1) {
|
||||
return false;
|
||||
} elseif ($value instanceof File) {
|
||||
return (string) $value->getPath() !== '';
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
if (is_null($value)) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user