diff --git a/docs/rector_rules_overview.md b/docs/rector_rules_overview.md index 977079d4327..05ae467d19d 100644 --- a/docs/rector_rules_overview.md +++ b/docs/rector_rules_overview.md @@ -1,4 +1,4 @@ -# 400 Rules Overview +# 401 Rules Overview
@@ -6,7 +6,7 @@ - [Arguments](#arguments) (5) -- [CodeQuality](#codequality) (77) +- [CodeQuality](#codequality) (78) - [CodingStyle](#codingstyle) (36) @@ -1268,6 +1268,19 @@ Simplify `is_array` and `empty` functions combination into a simple identical ch
+### SimplifyEmptyCheckOnEmptyArrayRector + +Simplify `empty` functions calls on empty arrays + +- class: [`Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector`](../rules/CodeQuality/Rector/Empty_/SimplifyEmptyCheckOnEmptyArrayRector.php) + +```diff +-$array = []; if(empty($values)) ++$array = []; if([] === $values) +``` + +
+ ### SimplifyForeachToArrayFilterRector Simplify foreach with function filtering to array filter diff --git a/rules/CodeQuality/Rector/Empty_/SimplifyEmptyCheckOnEmptyArrayRector.php b/rules/CodeQuality/Rector/Empty_/SimplifyEmptyCheckOnEmptyArrayRector.php new file mode 100644 index 00000000000..887b6fb2918 --- /dev/null +++ b/rules/CodeQuality/Rector/Empty_/SimplifyEmptyCheckOnEmptyArrayRector.php @@ -0,0 +1,60 @@ +> + */ + public function getNodeTypes() : array + { + return [Empty_::class]; + } + /** + * @param Empty_ $node $node + */ + public function refactorWithScope(Node $node, Scope $scope) : ?Node + { + if (!$this->isAllowedExpr($node->expr)) { + return null; + } + if (!$scope->getType($node->expr) instanceof ArrayType) { + return null; + } + return new Identical($node->expr, new Array_()); + } + private function isAllowedExpr(Node\Expr $expr) : bool + { + if ($expr instanceof Variable) { + return \true; + } + if ($expr instanceof PropertyFetch) { + return \true; + } + if ($expr instanceof StaticPropertyFetch) { + return \true; + } + return \false; + } +} diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 54743dde680..e6b01d390e9 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -17,12 +17,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '4140e7807611cb29cfcdd768e86a9203b0c69b9b'; + public const PACKAGE_VERSION = '07941b8f3dd7151db77df19243aed5c03a64cf63'; /** * @api * @var string */ - public const RELEASE_DATE = '2022-11-16 21:13:31'; + public const RELEASE_DATE = '2022-11-16 16:28:04'; /** * @var int */ diff --git a/vendor/autoload.php b/vendor/autoload.php index 07c358bf309..5e56ef22d63 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInita71e3fc1f9700a5d679aa07e296cbdbd::getLoader(); +return ComposerAutoloaderInit98342144ac67542bcb939585ac2614d0::getLoader(); diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 5ed52a4ef2e..d8f3dd2e7ae 100644 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -1168,6 +1168,7 @@ return array( 'Rector\\CodeQuality\\Rector\\Class_\\InlineConstructorDefaultToPropertyRector' => $baseDir . '/rules/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector.php', 'Rector\\CodeQuality\\Rector\\Concat\\JoinStringConcatRector' => $baseDir . '/rules/CodeQuality/Rector/Concat/JoinStringConcatRector.php', 'Rector\\CodeQuality\\Rector\\Do_\\DoWhileBreakFalseToIfElseRector' => $baseDir . '/rules/CodeQuality/Rector/Do_/DoWhileBreakFalseToIfElseRector.php', + 'Rector\\CodeQuality\\Rector\\Empty_\\SimplifyEmptyCheckOnEmptyArrayRector' => $baseDir . '/rules/CodeQuality/Rector/Empty_/SimplifyEmptyCheckOnEmptyArrayRector.php', 'Rector\\CodeQuality\\Rector\\Equal\\UseIdenticalOverEqualWithSameTypeRector' => $baseDir . '/rules/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php', 'Rector\\CodeQuality\\Rector\\Expression\\InlineIfToExplicitIfRector' => $baseDir . '/rules/CodeQuality/Rector/Expression/InlineIfToExplicitIfRector.php', 'Rector\\CodeQuality\\Rector\\Expression\\TernaryFalseExpressionToIfRector' => $baseDir . '/rules/CodeQuality/Rector/Expression/TernaryFalseExpressionToIfRector.php', diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 11b096a07e4..4756638caf2 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInita71e3fc1f9700a5d679aa07e296cbdbd +class ComposerAutoloaderInit98342144ac67542bcb939585ac2614d0 { private static $loader; @@ -22,19 +22,19 @@ class ComposerAutoloaderInita71e3fc1f9700a5d679aa07e296cbdbd return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInita71e3fc1f9700a5d679aa07e296cbdbd', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit98342144ac67542bcb939585ac2614d0', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInita71e3fc1f9700a5d679aa07e296cbdbd', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit98342144ac67542bcb939585ac2614d0', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInita71e3fc1f9700a5d679aa07e296cbdbd::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit98342144ac67542bcb939585ac2614d0::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $includeFiles = \Composer\Autoload\ComposerStaticInita71e3fc1f9700a5d679aa07e296cbdbd::$files; + $includeFiles = \Composer\Autoload\ComposerStaticInit98342144ac67542bcb939585ac2614d0::$files; foreach ($includeFiles as $fileIdentifier => $file) { - composerRequirea71e3fc1f9700a5d679aa07e296cbdbd($fileIdentifier, $file); + composerRequire98342144ac67542bcb939585ac2614d0($fileIdentifier, $file); } return $loader; @@ -46,7 +46,7 @@ class ComposerAutoloaderInita71e3fc1f9700a5d679aa07e296cbdbd * @param string $file * @return void */ -function composerRequirea71e3fc1f9700a5d679aa07e296cbdbd($fileIdentifier, $file) +function composerRequire98342144ac67542bcb939585ac2614d0($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index a0bf9fc7285..e6d5e1cf765 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInita71e3fc1f9700a5d679aa07e296cbdbd +class ComposerStaticInit98342144ac67542bcb939585ac2614d0 { public static $files = array ( 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', @@ -1413,6 +1413,7 @@ class ComposerStaticInita71e3fc1f9700a5d679aa07e296cbdbd 'Rector\\CodeQuality\\Rector\\Class_\\InlineConstructorDefaultToPropertyRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/Class_/InlineConstructorDefaultToPropertyRector.php', 'Rector\\CodeQuality\\Rector\\Concat\\JoinStringConcatRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/Concat/JoinStringConcatRector.php', 'Rector\\CodeQuality\\Rector\\Do_\\DoWhileBreakFalseToIfElseRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/Do_/DoWhileBreakFalseToIfElseRector.php', + 'Rector\\CodeQuality\\Rector\\Empty_\\SimplifyEmptyCheckOnEmptyArrayRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/Empty_/SimplifyEmptyCheckOnEmptyArrayRector.php', 'Rector\\CodeQuality\\Rector\\Equal\\UseIdenticalOverEqualWithSameTypeRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/Equal/UseIdenticalOverEqualWithSameTypeRector.php', 'Rector\\CodeQuality\\Rector\\Expression\\InlineIfToExplicitIfRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/Expression/InlineIfToExplicitIfRector.php', 'Rector\\CodeQuality\\Rector\\Expression\\TernaryFalseExpressionToIfRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/Expression/TernaryFalseExpressionToIfRector.php', @@ -3032,9 +3033,9 @@ class ComposerStaticInita71e3fc1f9700a5d679aa07e296cbdbd public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInita71e3fc1f9700a5d679aa07e296cbdbd::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInita71e3fc1f9700a5d679aa07e296cbdbd::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInita71e3fc1f9700a5d679aa07e296cbdbd::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit98342144ac67542bcb939585ac2614d0::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit98342144ac67542bcb939585ac2614d0::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit98342144ac67542bcb939585ac2614d0::$classMap; }, null, ClassLoader::class); }