Updated Rector to commit ae896432a906ca02a97c326295a29ced3c689998

ae896432a9 Move ArrayManipulator to rector-symfony, where only used (#4656)
This commit is contained in:
Tomas Votruba 2023-08-05 12:14:07 +00:00
parent 15f46b1693
commit 0a93085a9e
15 changed files with 80 additions and 107 deletions

View File

@ -9,22 +9,15 @@ use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Name\FullyQualified;
use Rector\Core\NodeAnalyzer\ExprAnalyzer;
use Rector\Core\NodeManipulator\ArrayManipulator;
final class ComplexNewAnalyzer
{
/**
* @readonly
* @var \Rector\Core\NodeManipulator\ArrayManipulator
*/
private $arrayManipulator;
/**
* @readonly
* @var \Rector\Core\NodeAnalyzer\ExprAnalyzer
*/
private $exprAnalyzer;
public function __construct(ArrayManipulator $arrayManipulator, ExprAnalyzer $exprAnalyzer)
public function __construct(ExprAnalyzer $exprAnalyzer)
{
$this->arrayManipulator = $arrayManipulator;
$this->exprAnalyzer = $exprAnalyzer;
}
public function isDynamic(New_ $new) : bool
@ -61,7 +54,7 @@ final class ComplexNewAnalyzer
}
private function isAllowedArray(Array_ $array) : bool
{
if (!$this->arrayManipulator->isDynamicArray($array)) {
if (!$this->exprAnalyzer->isDynamicArray($array)) {
return \true;
}
$arrayItems = $array->items;

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '9b03d8367cd3c69b36b8b1aedf458b191f46655a';
public const PACKAGE_VERSION = 'ae896432a906ca02a97c326295a29ced3c689998';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-08-05 11:25:26';
public const RELEASE_DATE = '2023-08-05 13:09:12';
/**
* @var int
*/

View File

@ -5,6 +5,7 @@ namespace Rector\Core\NodeAnalyzer;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\Variable;
@ -12,23 +13,15 @@ use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar;
use PhpParser\Node\Scalar\Encapsed;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\Scope;
use PHPStan\Type\MixedType;
use PHPStan\Type\UnionType;
use Rector\Core\Enum\ObjectReference;
use Rector\Core\NodeManipulator\ArrayManipulator;
use Rector\NodeTypeResolver\Node\AttributeKey;
final class ExprAnalyzer
{
/**
* @readonly
* @var \Rector\Core\NodeManipulator\ArrayManipulator
*/
private $arrayManipulator;
public function __construct(ArrayManipulator $arrayManipulator)
{
$this->arrayManipulator = $arrayManipulator;
}
public function isNonTypedFromParam(Expr $expr) : bool
{
if (!$expr instanceof Variable) {
@ -58,7 +51,22 @@ final class ExprAnalyzer
}
return !$this->isAllowedConstFetchOrClassConstFetch($expr);
}
return $this->arrayManipulator->isDynamicArray($expr);
return $this->isDynamicArray($expr);
}
public function isDynamicArray(Array_ $array) : bool
{
foreach ($array->items as $item) {
if (!$item instanceof ArrayItem) {
continue;
}
if (!$this->isAllowedArrayKey($item->key)) {
return \true;
}
if (!$this->isAllowedArrayValue($item->value)) {
return \true;
}
}
return \false;
}
private function isAllowedConstFetchOrClassConstFetch(Expr $expr) : bool
{
@ -77,4 +85,21 @@ final class ExprAnalyzer
}
return \false;
}
private function isAllowedArrayKey(?Expr $expr) : bool
{
if (!$expr instanceof Expr) {
return \true;
}
if ($expr instanceof String_) {
return \true;
}
return $expr instanceof LNumber;
}
private function isAllowedArrayValue(Expr $expr) : bool
{
if ($expr instanceof Array_) {
return !$this->isDynamicArray($expr);
}
return !$this->isDynamicExpr($expr);
}
}

2
vendor/autoload.php vendored
View File

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

View File

@ -1581,7 +1581,6 @@ return array(
'Rector\\Core\\NodeAnalyzer\\VariadicAnalyzer' => $baseDir . '/src/NodeAnalyzer/VariadicAnalyzer.php',
'Rector\\Core\\NodeDecorator\\CreatedByRuleDecorator' => $baseDir . '/src/NodeDecorator/CreatedByRuleDecorator.php',
'Rector\\Core\\NodeDecorator\\PropertyTypeDecorator' => $baseDir . '/src/NodeDecorator/PropertyTypeDecorator.php',
'Rector\\Core\\NodeManipulator\\ArrayManipulator' => $baseDir . '/src/NodeManipulator/ArrayManipulator.php',
'Rector\\Core\\NodeManipulator\\AssignManipulator' => $baseDir . '/src/NodeManipulator/AssignManipulator.php',
'Rector\\Core\\NodeManipulator\\BinaryOpManipulator' => $baseDir . '/src/NodeManipulator/BinaryOpManipulator.php',
'Rector\\Core\\NodeManipulator\\ClassConstManipulator' => $baseDir . '/src/NodeManipulator/ClassConstManipulator.php',
@ -2487,6 +2486,7 @@ return array(
'Rector\\Symfony\\NodeFactory\\OnSuccessLogoutClassMethodFactory' => $vendorDir . '/rector/rector-symfony/src/NodeFactory/OnSuccessLogoutClassMethodFactory.php',
'Rector\\Symfony\\NodeFactory\\ThisRenderFactory' => $vendorDir . '/rector/rector-symfony/src/NodeFactory/ThisRenderFactory.php',
'Rector\\Symfony\\NodeFinder\\EmptyReturnNodeFinder' => $vendorDir . '/rector/rector-symfony/src/NodeFinder/EmptyReturnNodeFinder.php',
'Rector\\Symfony\\NodeManipulator\\ArrayManipulator' => $vendorDir . '/rector/rector-symfony/src/NodeManipulator/ArrayManipulator.php',
'Rector\\Symfony\\NodeManipulator\\ClassManipulator' => $vendorDir . '/rector/rector-symfony/src/NodeManipulator/ClassManipulator.php',
'Rector\\Symfony\\PhpDocNode\\SymfonyRouteTagValueNodeFactory' => $vendorDir . '/rector/rector-symfony/src/PhpDocNode/SymfonyRouteTagValueNodeFactory.php',
'Rector\\Symfony\\Set\\FOSRestSetList' => $vendorDir . '/rector/rector-symfony/src/Set/FOSRestSetList.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitcf6a7b224b07ea957577e7892385954b
class ComposerAutoloaderInit19495756deacfcbb37b409ae48e3c3f5
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInitcf6a7b224b07ea957577e7892385954b
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitcf6a7b224b07ea957577e7892385954b', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit19495756deacfcbb37b409ae48e3c3f5', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitcf6a7b224b07ea957577e7892385954b', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit19495756deacfcbb37b409ae48e3c3f5', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitcf6a7b224b07ea957577e7892385954b::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit19495756deacfcbb37b409ae48e3c3f5::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInitcf6a7b224b07ea957577e7892385954b::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit19495756deacfcbb37b409ae48e3c3f5::$files;
$requireFile = \Closure::bind(static function ($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 ComposerStaticInitcf6a7b224b07ea957577e7892385954b
class ComposerStaticInit19495756deacfcbb37b409ae48e3c3f5
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -1835,7 +1835,6 @@ class ComposerStaticInitcf6a7b224b07ea957577e7892385954b
'Rector\\Core\\NodeAnalyzer\\VariadicAnalyzer' => __DIR__ . '/../..' . '/src/NodeAnalyzer/VariadicAnalyzer.php',
'Rector\\Core\\NodeDecorator\\CreatedByRuleDecorator' => __DIR__ . '/../..' . '/src/NodeDecorator/CreatedByRuleDecorator.php',
'Rector\\Core\\NodeDecorator\\PropertyTypeDecorator' => __DIR__ . '/../..' . '/src/NodeDecorator/PropertyTypeDecorator.php',
'Rector\\Core\\NodeManipulator\\ArrayManipulator' => __DIR__ . '/../..' . '/src/NodeManipulator/ArrayManipulator.php',
'Rector\\Core\\NodeManipulator\\AssignManipulator' => __DIR__ . '/../..' . '/src/NodeManipulator/AssignManipulator.php',
'Rector\\Core\\NodeManipulator\\BinaryOpManipulator' => __DIR__ . '/../..' . '/src/NodeManipulator/BinaryOpManipulator.php',
'Rector\\Core\\NodeManipulator\\ClassConstManipulator' => __DIR__ . '/../..' . '/src/NodeManipulator/ClassConstManipulator.php',
@ -2741,6 +2740,7 @@ class ComposerStaticInitcf6a7b224b07ea957577e7892385954b
'Rector\\Symfony\\NodeFactory\\OnSuccessLogoutClassMethodFactory' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeFactory/OnSuccessLogoutClassMethodFactory.php',
'Rector\\Symfony\\NodeFactory\\ThisRenderFactory' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeFactory/ThisRenderFactory.php',
'Rector\\Symfony\\NodeFinder\\EmptyReturnNodeFinder' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeFinder/EmptyReturnNodeFinder.php',
'Rector\\Symfony\\NodeManipulator\\ArrayManipulator' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeManipulator/ArrayManipulator.php',
'Rector\\Symfony\\NodeManipulator\\ClassManipulator' => __DIR__ . '/..' . '/rector/rector-symfony/src/NodeManipulator/ClassManipulator.php',
'Rector\\Symfony\\PhpDocNode\\SymfonyRouteTagValueNodeFactory' => __DIR__ . '/..' . '/rector/rector-symfony/src/PhpDocNode/SymfonyRouteTagValueNodeFactory.php',
'Rector\\Symfony\\Set\\FOSRestSetList' => __DIR__ . '/..' . '/rector/rector-symfony/src/Set/FOSRestSetList.php',
@ -3016,9 +3016,9 @@ class ComposerStaticInitcf6a7b224b07ea957577e7892385954b
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitcf6a7b224b07ea957577e7892385954b::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitcf6a7b224b07ea957577e7892385954b::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitcf6a7b224b07ea957577e7892385954b::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit19495756deacfcbb37b409ae48e3c3f5::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit19495756deacfcbb37b409ae48e3c3f5::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit19495756deacfcbb37b409ae48e3c3f5::$classMap;
}, null, ClassLoader::class);
}

View File

@ -2130,24 +2130,24 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "a0af12a8d67d0edefe6cffd22cdced62729a1dd9"
"reference": "73e258ca281de9a9db99d3f33df8afa1efcf31d3"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/a0af12a8d67d0edefe6cffd22cdced62729a1dd9",
"reference": "a0af12a8d67d0edefe6cffd22cdced62729a1dd9",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/73e258ca281de9a9db99d3f33df8afa1efcf31d3",
"reference": "73e258ca281de9a9db99d3f33df8afa1efcf31d3",
"shasum": ""
},
"require": {
"ext-xml": "*",
"php": ">=8.1",
"symfony\/string": "^6.1"
"symfony\/string": "^6.3"
},
"require-dev": {
"phpstan\/extension-installer": "^1.2",
"phpstan\/extension-installer": "^1.3",
"phpstan\/phpstan": "^1.9.2",
"phpstan\/phpstan-webmozart-assert": "^1.2",
"phpunit\/phpunit": "^10.0",
"phpunit\/phpunit": "^10.3",
"rector\/phpstan-rules": "^0.6",
"rector\/rector-generator": "^0.6",
"rector\/rector-src": "dev-main",
@ -2156,16 +2156,17 @@
"symfony\/security-http": "^6.1",
"symfony\/validator": "^6.2",
"symplify\/easy-ci": "^11.2",
"symplify\/easy-coding-standard": "^11.2",
"symplify\/easy-coding-standard": "^12.0",
"symplify\/phpstan-extensions": "^11.1",
"symplify\/phpstan-rules": "^11.2",
"symplify\/rule-doc-generator": "^11.2",
"symplify\/vendor-patches": "^11.2",
"tomasvotruba\/class-leak": "0.1.1.72",
"tomasvotruba\/cognitive-complexity": "^0.1",
"tomasvotruba\/type-coverage": "^0.2",
"tomasvotruba\/unused-public": "^0.1"
"tomasvotruba\/unused-public": "^0.2"
},
"time": "2023-07-14T10:30:55+00:00",
"time": "2023-08-05T11:57:58+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {

File diff suppressed because one or more lines are too long

View File

@ -9,7 +9,7 @@ namespace Rector\RectorInstaller;
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main dbc34e9'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main e560763'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 0438162'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main a0af12a'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main dbc34e9'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main e560763'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 0438162'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => array('includes' => array(0 => 'config/config.php')), 'version' => 'dev-main 73e258c'));
private function __construct()
{
}

View File

@ -6,13 +6,13 @@
"require": {
"php": ">=8.1",
"ext-xml": "*",
"symfony\/string": "^6.1"
"symfony\/string": "^6.3"
},
"require-dev": {
"phpstan\/extension-installer": "^1.2",
"phpstan\/extension-installer": "^1.3",
"phpstan\/phpstan": "^1.9.2",
"phpstan\/phpstan-webmozart-assert": "^1.2",
"phpunit\/phpunit": "^10.0",
"phpunit\/phpunit": "^10.3",
"rector\/phpstan-rules": "^0.6",
"rector\/rector-generator": "^0.6",
"rector\/rector-src": "dev-main",
@ -21,14 +21,15 @@
"symfony\/security-http": "^6.1",
"symfony\/validator": "^6.2",
"symplify\/easy-ci": "^11.2",
"symplify\/easy-coding-standard": "^11.2",
"symplify\/easy-coding-standard": "^12.0",
"symplify\/phpstan-extensions": "^11.1",
"symplify\/phpstan-rules": "^11.2",
"symplify\/rule-doc-generator": "^11.2",
"symplify\/vendor-patches": "^11.2",
"tomasvotruba\/class-leak": "0.1.1.72",
"tomasvotruba\/cognitive-complexity": "^0.1",
"tomasvotruba\/type-coverage": "^0.2",
"tomasvotruba\/unused-public": "^0.1"
"tomasvotruba\/unused-public": "^0.2"
},
"autoload": {
"psr-4": {

View File

@ -8,10 +8,10 @@ use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Scalar\String_;
use Rector\Core\NodeManipulator\ArrayManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\Symfony\NodeAnalyzer\FormAddMethodCallAnalyzer;
use Rector\Symfony\NodeAnalyzer\FormOptionsArrayMatcher;
use Rector\Symfony\NodeManipulator\ArrayManipulator;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
@ -21,7 +21,7 @@ final class ReadOnlyOptionToAttributeRector extends AbstractRector
{
/**
* @readonly
* @var \Rector\Core\NodeManipulator\ArrayManipulator
* @var \Rector\Symfony\NodeManipulator\ArrayManipulator
*/
private $arrayManipulator;
/**

View File

@ -8,6 +8,9 @@ use Rector\Symfony\Contract\Bridge\Symfony\Routing\SymfonyRoutesProviderInterfac
use Rector\Symfony\ValueObject\SymfonyRouteMetadata;
use RectorPrefix202308\Symfony\Component\Routing\RouterInterface;
use RectorPrefix202308\Webmozart\Assert\Assert;
/**
* @api part of AddRouteAnnotationRector
*/
final class SymfonyRoutesProvider implements SymfonyRoutesProviderInterface
{
/**

View File

@ -1,16 +1,12 @@
<?php
declare (strict_types=1);
namespace Rector\Core\NodeManipulator;
namespace Rector\Symfony\NodeManipulator;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\String_;
use Rector\ChangesReporting\Collector\RectorChangeCollector;
use Rector\Core\NodeAnalyzer\ExprAnalyzer;
use RectorPrefix202308\Symfony\Contracts\Service\Attribute\Required;
final class ArrayManipulator
{
/**
@ -18,39 +14,10 @@ final class ArrayManipulator
* @var \Rector\ChangesReporting\Collector\RectorChangeCollector
*/
private $rectorChangeCollector;
/**
* @var \Rector\Core\NodeAnalyzer\ExprAnalyzer
*/
private $exprAnalyzer;
public function __construct(RectorChangeCollector $rectorChangeCollector)
{
$this->rectorChangeCollector = $rectorChangeCollector;
}
/**
* @required
*/
public function autowire(ExprAnalyzer $exprAnalyzer) : void
{
$this->exprAnalyzer = $exprAnalyzer;
}
public function isDynamicArray(Array_ $array) : bool
{
foreach ($array->items as $item) {
if (!$item instanceof ArrayItem) {
continue;
}
if (!$this->isAllowedArrayKey($item->key)) {
return \true;
}
if (!$this->isAllowedArrayValue($item->value)) {
return \true;
}
}
return \false;
}
/**
* @api symfony
*/
public function addItemToArrayUnderKey(Array_ $array, ArrayItem $newArrayItem, string $key) : void
{
foreach ($array->items as $item) {
@ -67,9 +34,6 @@ final class ArrayManipulator
}
$array->items[] = new ArrayItem(new Array_([$newArrayItem]), new String_($key));
}
/**
* @api
*/
public function findItemInInArrayByKeyAndUnset(Array_ $array, string $keyName) : ?ArrayItem
{
foreach ($array->items as $i => $item) {
@ -90,28 +54,11 @@ final class ArrayManipulator
}
return null;
}
/**
* @api symfony
*/
public function hasKeyName(ArrayItem $arrayItem, string $name) : bool
private function hasKeyName(ArrayItem $arrayItem, string $name) : bool
{
if (!$arrayItem->key instanceof String_) {
return \false;
}
return $arrayItem->key->value === $name;
}
private function isAllowedArrayKey(?Expr $expr) : bool
{
if (!$expr instanceof Expr) {
return \true;
}
return \in_array(\get_class($expr), [String_::class, LNumber::class], \true);
}
private function isAllowedArrayValue(Expr $expr) : bool
{
if ($expr instanceof Array_) {
return !$this->isDynamicArray($expr);
}
return !$this->exprAnalyzer->isDynamicExpr($expr);
}
}

View File

@ -4,6 +4,9 @@ declare (strict_types=1);
namespace Rector\Symfony\Set;
use Rector\Set\Contract\SetListInterface;
/**
* @api used in public
*/
final class FOSRestSetList implements SetListInterface
{
/**