Updated Rector to commit 04c528e639778905387757ca3f7db6a3e48ac92f

04c528e639 Skip identical to false in SimplifyBoolIdenticalTrueRector, as exact comparison is stronger than negated expression (#4901)
This commit is contained in:
Tomas Votruba 2023-09-03 16:38:10 +00:00
parent 2415d543b0
commit d72f4cf839
8 changed files with 32 additions and 42 deletions

View File

@ -8,7 +8,6 @@ use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\Variable;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -25,6 +24,7 @@ class SomeClass
public function run(bool $value, string $items)
{
$match = in_array($value, $items, TRUE) === TRUE;
$match = in_array($value, $items, TRUE) !== FALSE;
}
}
@ -35,6 +35,7 @@ class SomeClass
public function run(bool $value, string $items)
{
$match = in_array($value, $items, TRUE);
$match = in_array($value, $items, TRUE);
}
}
@ -53,16 +54,13 @@ CODE_SAMPLE
*/
public function refactor(Node $node) : ?Node
{
if (!$this->valueResolver->isTrueOrFalse($node->left) && $this->getType($node->left)->isBoolean()->yes()) {
if ($this->isBooleanButNotTrueAndFalse($node->left)) {
return $this->processBoolTypeToNotBool($node, $node->left, $node->right);
}
if ($this->valueResolver->isTrueOrFalse($node->right)) {
return null;
if ($this->isBooleanButNotTrueAndFalse($node->right)) {
return $this->processBoolTypeToNotBool($node, $node->right, $node->left);
}
if (!$this->getType($node->right)->isBoolean()->yes()) {
return null;
}
return $this->processBoolTypeToNotBool($node, $node->right, $node->left);
return null;
}
private function processBoolTypeToNotBool(Node $node, Expr $leftExpr, Expr $rightExpr) : ?Expr
{
@ -79,18 +77,14 @@ CODE_SAMPLE
if ($this->valueResolver->isTrue($rightExpr)) {
return $leftExpr;
}
if ($this->valueResolver->isFalse($rightExpr)) {
// prevent !!
if ($leftExpr instanceof BooleanNot) {
return $leftExpr->expr;
}
// keep as it is, readable enough
if ($leftExpr instanceof Variable && $this->getType($leftExpr)->isBoolean()->yes()) {
return null;
}
return new BooleanNot($leftExpr);
// prevent double negation !!
if (!$this->valueResolver->isFalse($rightExpr)) {
return null;
}
return null;
if (!$leftExpr instanceof BooleanNot) {
return null;
}
return $leftExpr->expr;
}
private function refactorNotIdentical(Expr $leftExpr, Expr $rightExpr) : ?Expr
{
@ -102,4 +96,11 @@ CODE_SAMPLE
}
return null;
}
private function isBooleanButNotTrueAndFalse(Expr $expr) : bool
{
if ($this->valueResolver->isTrueOrFalse($expr)) {
return \false;
}
return $this->getType($expr)->isBoolean()->yes();
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'ca22ab5d024543bc804ec4f52b410aec42901f39';
public const PACKAGE_VERSION = '04c528e639778905387757ca3f7db6a3e48ac92f';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-09-03 18:23:17';
public const RELEASE_DATE = '2023-09-03 16:35:13';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit2e16242e118da93a47aba7accb5b3719::getLoader();
return ComposerAutoloaderInita186ca5eade703affbc9237477f5b118::getLoader();

View File

@ -91,7 +91,4 @@ if (\PHP_VERSION_ID < 80000) {
return include "phpvfscomposer://" . __DIR__ . '/..' . '/nikic/php-parser/bin/php-parse';
}
}
if (__FILE__ === \realpath($_SERVER['SCRIPT_NAME'])) {
$_SERVER['SCRIPT_NAME'] = \realpath(__DIR__ . '/..' . '/nikic/php-parser/bin/php-parse');
}
return include __DIR__ . '/..' . '/nikic/php-parser/bin/php-parse';

3
vendor/bin/phpstan vendored
View File

@ -91,7 +91,4 @@ if (\PHP_VERSION_ID < 80000) {
return include "phpvfscomposer://" . __DIR__ . '/..' . '/phpstan/phpstan/phpstan';
}
}
if (__FILE__ === \realpath($_SERVER['SCRIPT_NAME'])) {
$_SERVER['SCRIPT_NAME'] = \realpath(__DIR__ . '/..' . '/phpstan/phpstan/phpstan');
}
return include __DIR__ . '/..' . '/phpstan/phpstan/phpstan';

View File

@ -116,9 +116,4 @@ if (PHP_VERSION_ID < 80000) {
}
}
if (__FILE__ === realpath($_SERVER['SCRIPT_NAME'])) {
$_SERVER['SCRIPT_NAME'] = realpath(__DIR__ . '/..'.'/phpstan/phpstan/phpstan.phar');
}
return include __DIR__ . '/..'.'/phpstan/phpstan/phpstan.phar';

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit2e16242e118da93a47aba7accb5b3719
class ComposerAutoloaderInita186ca5eade703affbc9237477f5b118
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit2e16242e118da93a47aba7accb5b3719
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit2e16242e118da93a47aba7accb5b3719', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInita186ca5eade703affbc9237477f5b118', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit2e16242e118da93a47aba7accb5b3719', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInita186ca5eade703affbc9237477f5b118', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit2e16242e118da93a47aba7accb5b3719::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInita186ca5eade703affbc9237477f5b118::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit2e16242e118da93a47aba7accb5b3719::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInita186ca5eade703affbc9237477f5b118::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit2e16242e118da93a47aba7accb5b3719
class ComposerStaticInita186ca5eade703affbc9237477f5b118
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2611,9 +2611,9 @@ class ComposerStaticInit2e16242e118da93a47aba7accb5b3719
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit2e16242e118da93a47aba7accb5b3719::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit2e16242e118da93a47aba7accb5b3719::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit2e16242e118da93a47aba7accb5b3719::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInita186ca5eade703affbc9237477f5b118::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInita186ca5eade703affbc9237477f5b118::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInita186ca5eade703affbc9237477f5b118::$classMap;
}, null, ClassLoader::class);
}