mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-27 05:03:31 +00:00
improve SimplifyConditionsRector
This commit is contained in:
parent
b0bb0568ca
commit
c8e77079ac
|
@ -99,9 +99,13 @@ final class SimplifyConditionsRector extends AbstractRector
|
|||
return $binaryOpNode->right instanceof BinaryOp;
|
||||
}
|
||||
|
||||
private function createInversedBooleanOp(BinaryOp $binaryOpNode): BinaryOp
|
||||
private function createInversedBooleanOp(BinaryOp $binaryOpNode): ?BinaryOp
|
||||
{
|
||||
$inversedBinaryClass = $this->assignAndBinaryMap->getInversed($binaryOpNode);
|
||||
if ($inversedBinaryClass === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new $inversedBinaryClass($binaryOpNode->left, $binaryOpNode->right);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\CodeQuality\Tests\Rector\If_\SimplifyIfReturnBoolRetor\Wrong;
|
||||
|
||||
trait ValidatesAttributes
|
||||
{
|
||||
public function validateDimensions()
|
||||
{
|
||||
return !(true || true);
|
||||
}
|
||||
|
||||
public function function2($value, $secondValue)
|
||||
{
|
||||
return !(($value === true) || ($secondValue === true));
|
||||
}
|
||||
|
||||
public function function3($attribute, $value, $parameters)
|
||||
{
|
||||
return !($this->failsBasicDimensionChecks($parameters, $width, $height) ||
|
||||
$this->failsRatioCheck($parameters, $width, $height));
|
||||
}
|
||||
}
|
|
@ -26,6 +26,7 @@ final class SimplifyIfReturnBoolRectorTest extends AbstractRectorTestCase
|
|||
yield [__DIR__ . '/Wrong/wrong4.php.inc', __DIR__ . '/Correct/correct4.php.inc'];
|
||||
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'];
|
||||
}
|
||||
|
||||
protected function provideConfig(): string
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Rector\CodeQuality\Tests\Rector\If_\SimplifyIfReturnBoolRetor\Wrong;
|
||||
|
||||
trait ValidatesAttributes
|
||||
{
|
||||
public function validateDimensions()
|
||||
{
|
||||
if (true || true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function function2($value, $secondValue)
|
||||
{
|
||||
if (($value === true) || ($secondValue === true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function function3($attribute, $value, $parameters)
|
||||
{
|
||||
if ($this->failsBasicDimensionChecks($parameters, $width, $height) ||
|
||||
$this->failsRatioCheck($parameters, $width, $height)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user