fix SimplifyIfReturnBoolRector

This commit is contained in:
Tomas Votruba 2018-11-05 02:41:47 +01:00
parent a8a1198aa6
commit eb796af9fd
4 changed files with 43 additions and 0 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}