Updated Rector to commit 07941b8f3dd7151db77df19243aed5c03a64cf63

07941b8f3d [SimplifyEmptyCheckOnEmptyArrayRector] Add new rule #7485 (#3069)
This commit is contained in:
Tomas Votruba 2022-11-16 15:33:33 +00:00
parent 18779fffd6
commit 4c8be8a104
7 changed files with 91 additions and 16 deletions

View File

@ -1,4 +1,4 @@
# 400 Rules Overview
# 401 Rules Overview
<br>
@ -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
<br>
### 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)
```
<br>
### SimplifyForeachToArrayFilterRector
Simplify foreach with function filtering to array filter

View File

@ -0,0 +1,60 @@
<?php
declare (strict_types=1);
namespace Rector\CodeQuality\Rector\Empty_;
use PhpParser\Node;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\BinaryOp\Identical;
use PhpParser\Node\Expr\Empty_;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Expr\Variable;
use PHPStan\Analyser\Scope;
use PHPStan\Type\ArrayType;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @see \Rector\Tests\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRectorTest\SimplifyEmptyCheckOnEmptyArrayRectorTest
*/
final class SimplifyEmptyCheckOnEmptyArrayRector extends AbstractScopeAwareRector
{
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Simplify `empty` functions calls on empty arrays', [new CodeSample('$array = []; if(empty($values))', '$array = []; if([] === $values)')]);
}
/**
* @return array<class-string<Node>>
*/
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;
}
}

View File

@ -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
*/

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInita71e3fc1f9700a5d679aa07e296cbdbd::getLoader();
return ComposerAutoloaderInit98342144ac67542bcb939585ac2614d0::getLoader();

View File

@ -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',

View File

@ -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;

View File

@ -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);
}