diff --git a/rules/CodeQuality/Rector/Ternary/SwitchNegatedTernaryRector.php b/rules/CodeQuality/Rector/Ternary/SwitchNegatedTernaryRector.php index 43d2fcfb42c..7b7f691cd47 100644 --- a/rules/CodeQuality/Rector/Ternary/SwitchNegatedTernaryRector.php +++ b/rules/CodeQuality/Rector/Ternary/SwitchNegatedTernaryRector.php @@ -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; } } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index ebac0b01082..51e06c97a5e 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -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__); diff --git a/src/PhpParser/Node/Value/TernaryBracketWrapper.php b/src/PhpParser/Node/Value/TernaryBracketWrapper.php new file mode 100644 index 00000000000..49d056c1565 --- /dev/null +++ b/src/PhpParser/Node/Value/TernaryBracketWrapper.php @@ -0,0 +1,15 @@ +setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::KIND, 'wrapped_with_brackets'); + $ternary->setAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::ORIGINAL_NODE, null); + } +} diff --git a/src/PhpParser/Printer/BetterStandardPrinter.php b/src/PhpParser/Printer/BetterStandardPrinter.php index 5d0a2292aff..5c4ae9ffc69 100644 --- a/src/PhpParser/Printer/BetterStandardPrinter.php +++ b/src/PhpParser/Printer/BetterStandardPrinter.php @@ -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 diff --git a/vendor/autoload.php b/vendor/autoload.php index e2587ee7073..280ff6f37ea 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit398b57529da626c6aae25674725e22ec::getLoader(); +return ComposerAutoloaderInitaecaf942a0dec633c23d6da797bc67e1::getLoader(); diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index abff83888a6..6ab5aca8070 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -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', diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 2ee6ce91fc8..97803afef6a 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -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; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 3fb8bb8eeaa..137503d72f4 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -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); } diff --git a/vendor/scoper-autoload.php b/vendor/scoper-autoload.php index 0adf05f37b3..544a100c3bc 100644 --- a/vendor/scoper-autoload.php +++ b/vendor/scoper-autoload.php @@ -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')) {