Updated Rector to commit a667293626

26d5ed893e fix cs c2fd4d22c9 apply Rector a667293626 Merge pull request #1622 from rectorphp/tv-fix-cs
This commit is contained in:
Tomas Votruba 2022-01-04 13:59:13 +00:00
parent 36ab25f533
commit 6f207e80a2
8 changed files with 58 additions and 47 deletions

View File

@ -22,20 +22,20 @@ final class BinaryOpConditionsCollector
* @param class-string<BinaryOp> $binaryOpClass
* @return array<int, Expr>
*/
public function findConditions(\PhpParser\Node\Expr $binaryOp, string $binaryOpClass) : array
public function findConditions(\PhpParser\Node\Expr $expr, string $binaryOpClass) : array
{
if (\get_class($binaryOp) !== $binaryOpClass) {
if (\get_class($expr) !== $binaryOpClass) {
// Different binary operators, as well as non-BinaryOp expressions
// are considered trivial case of a single operand (no operators).
return [$binaryOp];
return [$expr];
}
$conditions = [];
/** @var BinaryOp|Expr $binaryOp */
while ($binaryOp instanceof \PhpParser\Node\Expr\BinaryOp) {
$conditions[] = $binaryOp->right;
$binaryOp = $binaryOp->left;
if (\get_class($binaryOp) !== $binaryOpClass) {
$conditions[] = $binaryOp;
/** @var BinaryOp|Expr $expr */
while ($expr instanceof \PhpParser\Node\Expr\BinaryOp) {
$conditions[] = $expr->right;
$expr = $expr->left;
if (\get_class($expr) !== $binaryOpClass) {
$conditions[] = $expr;
break;
}
}

View File

@ -3,9 +3,13 @@
declare (strict_types=1);
namespace Rector\NodeCollector;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp;
use Rector\NodeTypeResolver\Node\AttributeKey;
/**
* @see \Rector\Tests\NodeCollector\BinaryOpTreeRootLocatorTest
*/
final class BinaryOpTreeRootLocator
{
/**
@ -18,18 +22,26 @@ final class BinaryOpTreeRootLocator
*/
public function findOperationRoot(\PhpParser\Node\Expr $expr, string $binaryOpClass) : \PhpParser\Node\Expr
{
/** @var ?Expr $parentNode */
$parentNode = $expr->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);
if ($parentNode === null || \get_class($parentNode) !== $binaryOpClass) {
if (!$parentNode instanceof \PhpParser\Node) {
return $expr;
}
\assert($parentNode instanceof \PhpParser\Node\Expr\BinaryOp);
$isLeftChild = $parentNode->left === $expr;
$isRightChild = $parentNode->right === $expr;
$isRightChildAndNotBinaryOp = $isRightChild && \get_class($expr) !== $binaryOpClass;
if ($isLeftChild || $isRightChildAndNotBinaryOp) {
if (\get_class($parentNode) !== $binaryOpClass) {
return $expr;
}
if (!$parentNode instanceof \PhpParser\Node\Expr\BinaryOp) {
return $expr;
}
if ($parentNode->left === $expr) {
return $this->findOperationRoot($parentNode, $binaryOpClass);
}
return $expr;
$isRightChild = $parentNode->right === $expr;
if (!$isRightChild) {
return $expr;
}
if (\get_class($expr) === $binaryOpClass) {
return $expr;
}
return $this->findOperationRoot($parentNode, $binaryOpClass);
}
}

View File

@ -81,37 +81,36 @@ CODE_SAMPLE
// Store the value into a temporary variable to prevent running possible side-effects twice
// when the expression is e.g. function.
$variable = $this->createVariable($node);
$throwableCheck = new \PhpParser\Node\Expr\Instanceof_(new \PhpParser\Node\Expr\Assign($variable, $node->expr), $node->class);
$instanceof = new \PhpParser\Node\Expr\Instanceof_(new \PhpParser\Node\Expr\Assign($variable, $node->expr), $node->class);
$exceptionFallbackCheck = $this->createFallbackCheck($variable);
$expression = new \PhpParser\Node\Expr\BinaryOp\BooleanOr($throwableCheck, $exceptionFallbackCheck);
return $expression;
return new \PhpParser\Node\Expr\BinaryOp\BooleanOr($instanceof, $exceptionFallbackCheck);
}
private function createVariable(\PhpParser\Node\Expr\Instanceof_ $expr) : \PhpParser\Node\Expr\Variable
private function createVariable(\PhpParser\Node\Expr\Instanceof_ $instanceof) : \PhpParser\Node\Expr\Variable
{
$currentStmt = $expr->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CURRENT_STATEMENT);
$currentStmt = $instanceof->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::CURRENT_STATEMENT);
$scope = $currentStmt->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE);
return new \PhpParser\Node\Expr\Variable($this->variableNaming->createCountedValueName('throwable', $scope));
}
/**
* Also checks similar manual transformations.
*/
private function isAlreadyTransformed(\PhpParser\Node\Expr\Instanceof_ $instanceof_) : bool
private function isAlreadyTransformed(\PhpParser\Node\Expr\Instanceof_ $instanceof) : bool
{
/** @var Node $parentNode */
$parentNode = $instanceof_->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);
$parentNode = $instanceof->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PARENT_NODE);
if (!$parentNode instanceof \PhpParser\Node\Expr\BinaryOp\BooleanOr) {
return \false;
}
$hasVariableToFindInDisjunction = ($var = $instanceof_->expr) instanceof \PhpParser\Node\Expr\Variable || $instanceof_->expr instanceof \PhpParser\Node\Expr\Assign && ($var = $instanceof_->expr->var) instanceof \PhpParser\Node\Expr\Variable;
$hasVariableToFindInDisjunction = ($var = $instanceof->expr) instanceof \PhpParser\Node\Expr\Variable || $instanceof->expr instanceof \PhpParser\Node\Expr\Assign && ($var = $instanceof->expr->var) instanceof \PhpParser\Node\Expr\Variable;
if (!$hasVariableToFindInDisjunction) {
return \false;
}
$disjunctionTree = $this->binaryOpTreeRootLocator->findOperationRoot($instanceof_, \PhpParser\Node\Expr\BinaryOp\BooleanOr::class);
$disjunctionTree = $this->binaryOpTreeRootLocator->findOperationRoot($instanceof, \PhpParser\Node\Expr\BinaryOp\BooleanOr::class);
$disjuncts = $this->binaryOpConditionsCollector->findConditions($disjunctionTree, \PhpParser\Node\Expr\BinaryOp\BooleanOr::class);
// If we transformed it ourselves, the second check can only be to the right
// since it uses the assigned variable.
if ($instanceof_->expr instanceof \PhpParser\Node\Expr\Assign) {
$index = \array_search($instanceof_, $disjuncts, \true);
if ($instanceof->expr instanceof \PhpParser\Node\Expr\Assign) {
$index = \array_search($instanceof, $disjuncts, \true);
if ($index !== \false) {
$disjuncts = \array_slice($disjuncts, $index);
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '373afbaadd32088d98f2f1a38107836eeb038e89';
public const PACKAGE_VERSION = 'a66729362638e40ab2e3b985575598b70d7042df';
/**
* @var string
*/
public const RELEASE_DATE = '2022-01-04 14:13:46';
public const RELEASE_DATE = '2022-01-04 14:48:44';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20220104\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit690b0ef5a80e46b80f11cf1ae276422e::getLoader();
return ComposerAutoloaderIniteb7e441e82dde7a958aa965c91e6282d::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit690b0ef5a80e46b80f11cf1ae276422e
class ComposerAutoloaderIniteb7e441e82dde7a958aa965c91e6282d
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInit690b0ef5a80e46b80f11cf1ae276422e
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit690b0ef5a80e46b80f11cf1ae276422e', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderIniteb7e441e82dde7a958aa965c91e6282d', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit690b0ef5a80e46b80f11cf1ae276422e', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderIniteb7e441e82dde7a958aa965c91e6282d', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit690b0ef5a80e46b80f11cf1ae276422e::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticIniteb7e441e82dde7a958aa965c91e6282d::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,12 +42,12 @@ class ComposerAutoloaderInit690b0ef5a80e46b80f11cf1ae276422e
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit690b0ef5a80e46b80f11cf1ae276422e::$files;
$includeFiles = Composer\Autoload\ComposerStaticIniteb7e441e82dde7a958aa965c91e6282d::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire690b0ef5a80e46b80f11cf1ae276422e($fileIdentifier, $file);
composerRequireeb7e441e82dde7a958aa965c91e6282d($fileIdentifier, $file);
}
return $loader;
@ -59,7 +59,7 @@ class ComposerAutoloaderInit690b0ef5a80e46b80f11cf1ae276422e
* @param string $file
* @return void
*/
function composerRequire690b0ef5a80e46b80f11cf1ae276422e($fileIdentifier, $file)
function composerRequireeb7e441e82dde7a958aa965c91e6282d($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 ComposerStaticInit690b0ef5a80e46b80f11cf1ae276422e
class ComposerStaticIniteb7e441e82dde7a958aa965c91e6282d
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -3850,9 +3850,9 @@ class ComposerStaticInit690b0ef5a80e46b80f11cf1ae276422e
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit690b0ef5a80e46b80f11cf1ae276422e::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit690b0ef5a80e46b80f11cf1ae276422e::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit690b0ef5a80e46b80f11cf1ae276422e::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticIniteb7e441e82dde7a958aa965c91e6282d::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticIniteb7e441e82dde7a958aa965c91e6282d::$prefixDirsPsr4;
$loader->classMap = ComposerStaticIniteb7e441e82dde7a958aa965c91e6282d::$classMap;
}, null, ClassLoader::class);
}

View File

@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20220104\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit690b0ef5a80e46b80f11cf1ae276422e', false) && !interface_exists('ComposerAutoloaderInit690b0ef5a80e46b80f11cf1ae276422e', false) && !trait_exists('ComposerAutoloaderInit690b0ef5a80e46b80f11cf1ae276422e', false)) {
spl_autoload_call('RectorPrefix20220104\ComposerAutoloaderInit690b0ef5a80e46b80f11cf1ae276422e');
if (!class_exists('ComposerAutoloaderIniteb7e441e82dde7a958aa965c91e6282d', false) && !interface_exists('ComposerAutoloaderIniteb7e441e82dde7a958aa965c91e6282d', false) && !trait_exists('ComposerAutoloaderIniteb7e441e82dde7a958aa965c91e6282d', false)) {
spl_autoload_call('RectorPrefix20220104\ComposerAutoloaderIniteb7e441e82dde7a958aa965c91e6282d');
}
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
spl_autoload_call('RectorPrefix20220104\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -78,9 +78,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220104\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire690b0ef5a80e46b80f11cf1ae276422e')) {
function composerRequire690b0ef5a80e46b80f11cf1ae276422e() {
return \RectorPrefix20220104\composerRequire690b0ef5a80e46b80f11cf1ae276422e(...func_get_args());
if (!function_exists('composerRequireeb7e441e82dde7a958aa965c91e6282d')) {
function composerRequireeb7e441e82dde7a958aa965c91e6282d() {
return \RectorPrefix20220104\composerRequireeb7e441e82dde7a958aa965c91e6282d(...func_get_args());
}
}
if (!function_exists('scanPath')) {