mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 22:08:00 +01:00
Updated Rector to commit 5a863f65484038059143b6d0b4fae8a275f9e5e8
5a863f6548
[CodeQuality] Handle Nested Ternary on SwitchNegatedTernaryRector to have parenthesis (#397)
This commit is contained in:
parent
85f7b6113a
commit
bda9a60c30
@ -6,6 +6,7 @@ namespace Rector\CodeQuality\Rector\Ternary;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\BooleanNot;
|
||||
use PhpParser\Node\Expr\Ternary;
|
||||
use Rector\Core\PhpParser\Node\Value\TernaryBracketWrapper;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
@ -14,6 +15,14 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
*/
|
||||
final class SwitchNegatedTernaryRector extends \Rector\Core\Rector\AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var \Rector\Core\PhpParser\Node\Value\TernaryBracketWrapper
|
||||
*/
|
||||
private $ternaryBracketWrapper;
|
||||
public function __construct(\Rector\Core\PhpParser\Node\Value\TernaryBracketWrapper $ternaryBracketWrapper)
|
||||
{
|
||||
$this->ternaryBracketWrapper = $ternaryBracketWrapper;
|
||||
}
|
||||
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Switch negated ternary condition rector', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
|
||||
@ -60,6 +69,9 @@ CODE_SAMPLE
|
||||
}
|
||||
$node->cond = $node->cond->expr;
|
||||
[$node->if, $node->else] = [$node->else, $node->if];
|
||||
if ($node->if instanceof \PhpParser\Node\Expr\Ternary) {
|
||||
$this->ternaryBracketWrapper->wrapWithBracket($node->if);
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,11 @@ final class VersionResolver
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'd5cd2bcc356ef008b82ba6502fbe6c8de4efc8d3';
|
||||
public const PACKAGE_VERSION = '5a863f65484038059143b6d0b4fae8a275f9e5e8';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2021-07-07 16:17:19';
|
||||
public const RELEASE_DATE = '2021-07-07 16:19:25';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20210707\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
15
src/PhpParser/Node/Value/TernaryBracketWrapper.php
Normal file
15
src/PhpParser/Node/Value/TernaryBracketWrapper.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\PhpParser\Node\Value;
|
||||
|
||||
use PhpParser\Node\Expr\Ternary;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
final class TernaryBracketWrapper
|
||||
{
|
||||
public function wrapWithBracket(\PhpParser\Node\Expr\Ternary $ternary) : void
|
||||
{
|
||||
$ternary->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::KIND, 'wrapped_with_brackets');
|
||||
$ternary->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::ORIGINAL_NODE, null);
|
||||
}
|
||||
}
|
@ -7,6 +7,7 @@ use RectorPrefix20210707\Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Array_;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\Ternary;
|
||||
use PhpParser\Node\Expr\Yield_;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
@ -319,6 +320,18 @@ final class BetterStandardPrinter extends \PhpParser\PrettyPrinter\Standard
|
||||
$declareString = parent::pStmt_Declare($declare);
|
||||
return \RectorPrefix20210707\Nette\Utils\Strings::replace($declareString, '#\\s+#', '');
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\Ternary $ternary
|
||||
*/
|
||||
protected function pExpr_Ternary($ternary) : string
|
||||
{
|
||||
$kind = $ternary->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::KIND);
|
||||
if ($kind === 'wrapped_with_brackets') {
|
||||
$pExprTernary = parent::pExpr_Ternary($ternary);
|
||||
return '(' . $pExprTernary . ')';
|
||||
}
|
||||
return parent::pExpr_Ternary($ternary);
|
||||
}
|
||||
/**
|
||||
* Remove extra \\ from FQN use imports, for easier use in the code
|
||||
* @param \PhpParser\Node\Stmt\Use_ $use
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -4,4 +4,4 @@
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit398b57529da626c6aae25674725e22ec::getLoader();
|
||||
return ComposerAutoloaderInitaecaf942a0dec633c23d6da797bc67e1::getLoader();
|
||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -1901,6 +1901,7 @@ return array(
|
||||
'Rector\\Core\\PhpParser\\Node\\BetterNodeFinder' => $baseDir . '/src/PhpParser/Node/BetterNodeFinder.php',
|
||||
'Rector\\Core\\PhpParser\\Node\\CustomNode\\FileWithoutNamespace' => $baseDir . '/src/PhpParser/Node/CustomNode/FileWithoutNamespace.php',
|
||||
'Rector\\Core\\PhpParser\\Node\\NodeFactory' => $baseDir . '/src/PhpParser/Node/NodeFactory.php',
|
||||
'Rector\\Core\\PhpParser\\Node\\Value\\TernaryBracketWrapper' => $baseDir . '/src/PhpParser/Node/Value/TernaryBracketWrapper.php',
|
||||
'Rector\\Core\\PhpParser\\Node\\Value\\ValueResolver' => $baseDir . '/src/PhpParser/Node/Value/ValueResolver.php',
|
||||
'Rector\\Core\\PhpParser\\Parser\\InlineCodeParser' => $baseDir . '/src/PhpParser/Parser/InlineCodeParser.php',
|
||||
'Rector\\Core\\PhpParser\\Parser\\NikicPhpParserFactory' => $baseDir . '/src/PhpParser/Parser/NikicPhpParserFactory.php',
|
||||
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit398b57529da626c6aae25674725e22ec
|
||||
class ComposerAutoloaderInitaecaf942a0dec633c23d6da797bc67e1
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,15 +22,15 @@ class ComposerAutoloaderInit398b57529da626c6aae25674725e22ec
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit398b57529da626c6aae25674725e22ec', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitaecaf942a0dec633c23d6da797bc67e1', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit398b57529da626c6aae25674725e22ec', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitaecaf942a0dec633c23d6da797bc67e1', '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\ComposerStaticInit398b57529da626c6aae25674725e22ec::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitaecaf942a0dec633c23d6da797bc67e1::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
@ -42,19 +42,19 @@ class ComposerAutoloaderInit398b57529da626c6aae25674725e22ec
|
||||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit398b57529da626c6aae25674725e22ec::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInitaecaf942a0dec633c23d6da797bc67e1::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire398b57529da626c6aae25674725e22ec($fileIdentifier, $file);
|
||||
composerRequireaecaf942a0dec633c23d6da797bc67e1($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequire398b57529da626c6aae25674725e22ec($fileIdentifier, $file)
|
||||
function composerRequireaecaf942a0dec633c23d6da797bc67e1($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit398b57529da626c6aae25674725e22ec
|
||||
class ComposerStaticInitaecaf942a0dec633c23d6da797bc67e1
|
||||
{
|
||||
public static $files = array (
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||
@ -2266,6 +2266,7 @@ class ComposerStaticInit398b57529da626c6aae25674725e22ec
|
||||
'Rector\\Core\\PhpParser\\Node\\BetterNodeFinder' => __DIR__ . '/../..' . '/src/PhpParser/Node/BetterNodeFinder.php',
|
||||
'Rector\\Core\\PhpParser\\Node\\CustomNode\\FileWithoutNamespace' => __DIR__ . '/../..' . '/src/PhpParser/Node/CustomNode/FileWithoutNamespace.php',
|
||||
'Rector\\Core\\PhpParser\\Node\\NodeFactory' => __DIR__ . '/../..' . '/src/PhpParser/Node/NodeFactory.php',
|
||||
'Rector\\Core\\PhpParser\\Node\\Value\\TernaryBracketWrapper' => __DIR__ . '/../..' . '/src/PhpParser/Node/Value/TernaryBracketWrapper.php',
|
||||
'Rector\\Core\\PhpParser\\Node\\Value\\ValueResolver' => __DIR__ . '/../..' . '/src/PhpParser/Node/Value/ValueResolver.php',
|
||||
'Rector\\Core\\PhpParser\\Parser\\InlineCodeParser' => __DIR__ . '/../..' . '/src/PhpParser/Parser/InlineCodeParser.php',
|
||||
'Rector\\Core\\PhpParser\\Parser\\NikicPhpParserFactory' => __DIR__ . '/../..' . '/src/PhpParser/Parser/NikicPhpParserFactory.php',
|
||||
@ -3866,9 +3867,9 @@ class ComposerStaticInit398b57529da626c6aae25674725e22ec
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit398b57529da626c6aae25674725e22ec::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit398b57529da626c6aae25674725e22ec::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit398b57529da626c6aae25674725e22ec::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitaecaf942a0dec633c23d6da797bc67e1::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitaecaf942a0dec633c23d6da797bc67e1::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitaecaf942a0dec633c23d6da797bc67e1::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
@ -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('RectorPrefix20210707\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInit398b57529da626c6aae25674725e22ec', false) && !interface_exists('ComposerAutoloaderInit398b57529da626c6aae25674725e22ec', false) && !trait_exists('ComposerAutoloaderInit398b57529da626c6aae25674725e22ec', false)) {
|
||||
spl_autoload_call('RectorPrefix20210707\ComposerAutoloaderInit398b57529da626c6aae25674725e22ec');
|
||||
if (!class_exists('ComposerAutoloaderInitaecaf942a0dec633c23d6da797bc67e1', false) && !interface_exists('ComposerAutoloaderInitaecaf942a0dec633c23d6da797bc67e1', false) && !trait_exists('ComposerAutoloaderInitaecaf942a0dec633c23d6da797bc67e1', false)) {
|
||||
spl_autoload_call('RectorPrefix20210707\ComposerAutoloaderInitaecaf942a0dec633c23d6da797bc67e1');
|
||||
}
|
||||
if (!class_exists('Doctrine\Inflector\Inflector', false) && !interface_exists('Doctrine\Inflector\Inflector', false) && !trait_exists('Doctrine\Inflector\Inflector', false)) {
|
||||
spl_autoload_call('RectorPrefix20210707\Doctrine\Inflector\Inflector');
|
||||
@ -3308,9 +3308,9 @@ if (!function_exists('print_node')) {
|
||||
return \RectorPrefix20210707\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequire398b57529da626c6aae25674725e22ec')) {
|
||||
function composerRequire398b57529da626c6aae25674725e22ec() {
|
||||
return \RectorPrefix20210707\composerRequire398b57529da626c6aae25674725e22ec(...func_get_args());
|
||||
if (!function_exists('composerRequireaecaf942a0dec633c23d6da797bc67e1')) {
|
||||
function composerRequireaecaf942a0dec633c23d6da797bc67e1() {
|
||||
return \RectorPrefix20210707\composerRequireaecaf942a0dec633c23d6da797bc67e1(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('parseArgs')) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user