Updated Rector to commit d42fd12f4ad38f29f8e7f3fd19d9bb740f0f9356

d42fd12f4a Improve IfToSpaceshipRector (#3871)
This commit is contained in:
Tomas Votruba 2023-05-16 13:09:11 +00:00
parent 3847b0c3b5
commit 56836f25e8
5 changed files with 53 additions and 30 deletions

View File

@ -33,9 +33,6 @@ final class BattleshipTernaryAnalyzer
*/
public function isGreaterLowerCompareReturnOneAndMinusOne(Ternary $ternary, ComparedExprs $comparedExprs) : ?string
{
if (!$ternary->if instanceof Expr) {
return null;
}
if ($ternary->cond instanceof Greater) {
return $this->evaluateGreater($ternary->cond, $ternary, $comparedExprs);
}
@ -56,19 +53,16 @@ final class BattleshipTernaryAnalyzer
if (!$ternary->if instanceof Expr) {
return null;
}
if (!$this->nodeComparator->areNodesEqual($greater->left, $comparedExprs->getFirstExpr())) {
if ($this->nodeComparator->areNodesEqual($greater->left, $comparedExprs->getFirstExpr()) && $this->nodeComparator->areNodesEqual($greater->right, $comparedExprs->getSecondExpr())) {
return $this->evaluateTernaryDesc($ternary);
}
if (!$this->nodeComparator->areNodesEqual($greater->right, $comparedExprs->getFirstExpr())) {
return null;
}
if (!$this->nodeComparator->areNodesEqual($greater->right, $comparedExprs->getSecondExpr())) {
if (!$this->nodeComparator->areNodesEqual($greater->left, $comparedExprs->getSecondExpr())) {
return null;
}
if ($this->isValueOneAndMinusOne($ternary->if, $ternary->else)) {
return BattleshipCompareOrder::DESC;
}
if ($this->isValueOneAndMinusOne($ternary->else, $ternary->if)) {
return BattleshipCompareOrder::ASC;
}
return null;
return $this->evaluateTernaryAsc($ternary);
}
/**
* We look for:
@ -82,10 +76,30 @@ final class BattleshipTernaryAnalyzer
if (!$ternary->if instanceof Expr) {
return null;
}
if (!$this->nodeComparator->areNodesEqual($smaller->left, $comparedExprs->getFirstExpr())) {
if ($this->nodeComparator->areNodesEqual($smaller->left, $comparedExprs->getFirstExpr()) && $this->nodeComparator->areNodesEqual($smaller->right, $comparedExprs->getSecondExpr())) {
return $this->evaluateTernaryAsc($ternary);
}
if (!$this->nodeComparator->areNodesEqual($smaller->right, $comparedExprs->getFirstExpr())) {
return null;
}
if (!$this->nodeComparator->areNodesEqual($smaller->right, $comparedExprs->getSecondExpr())) {
if (!$this->nodeComparator->areNodesEqual($smaller->left, $comparedExprs->getSecondExpr())) {
return null;
}
return $this->evaluateTernaryDesc($ternary);
}
private function isValueOneAndMinusOne(Expr $firstExpr, Expr $seconcExpr) : bool
{
if (!$this->valueResolver->isValue($firstExpr, 1)) {
return \false;
}
return $this->valueResolver->isValue($seconcExpr, -1);
}
/**
* @return BattleshipCompareOrder::*|null
*/
private function evaluateTernaryAsc(Ternary $ternary) : ?string
{
if (!$ternary->if instanceof Expr) {
return null;
}
if ($this->isValueOneAndMinusOne($ternary->if, $ternary->else)) {
@ -96,11 +110,20 @@ final class BattleshipTernaryAnalyzer
}
return null;
}
private function isValueOneAndMinusOne(Expr $firstExpr, Expr $seconcExpr) : bool
/**
* @return BattleshipCompareOrder::*|null
*/
private function evaluateTernaryDesc(Ternary $ternary) : ?string
{
if (!$this->valueResolver->isValue($firstExpr, 1)) {
return \false;
if (!$ternary->if instanceof Expr) {
return null;
}
return $this->valueResolver->isValue($seconcExpr, -1);
if ($this->isValueOneAndMinusOne($ternary->if, $ternary->else)) {
return BattleshipCompareOrder::DESC;
}
if ($this->isValueOneAndMinusOne($ternary->else, $ternary->if)) {
return BattleshipCompareOrder::ASC;
}
return null;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'd2ae72e1fe616bb5c2d98c497a59991cfb5cca55';
public const PACKAGE_VERSION = 'd42fd12f4ad38f29f8e7f3fd19d9bb740f0f9356';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-05-16 12:46:18';
public const RELEASE_DATE = '2023-05-16 13:05:26';
/**
* @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 ComposerAutoloaderInit527c958222df83203b5281f72b24c52b::getLoader();
return ComposerAutoloaderInit620bf12bca18fa37561a8a23c052d72b::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit527c958222df83203b5281f72b24c52b
class ComposerAutoloaderInit620bf12bca18fa37561a8a23c052d72b
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit527c958222df83203b5281f72b24c52b
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit527c958222df83203b5281f72b24c52b', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit620bf12bca18fa37561a8a23c052d72b', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit527c958222df83203b5281f72b24c52b', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit620bf12bca18fa37561a8a23c052d72b', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit527c958222df83203b5281f72b24c52b::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit620bf12bca18fa37561a8a23c052d72b::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit527c958222df83203b5281f72b24c52b::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit620bf12bca18fa37561a8a23c052d72b::$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 ComposerStaticInit527c958222df83203b5281f72b24c52b
class ComposerStaticInit620bf12bca18fa37561a8a23c052d72b
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3106,9 +3106,9 @@ class ComposerStaticInit527c958222df83203b5281f72b24c52b
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit527c958222df83203b5281f72b24c52b::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit527c958222df83203b5281f72b24c52b::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit527c958222df83203b5281f72b24c52b::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit620bf12bca18fa37561a8a23c052d72b::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit620bf12bca18fa37561a8a23c052d72b::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit620bf12bca18fa37561a8a23c052d72b::$classMap;
}, null, ClassLoader::class);
}