Skip to content

Commit

Permalink
Rector 0.15.23
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Mar 22, 2023
1 parent b5afb12 commit f4984eb
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '5e29a35bb60f92bece6fede8080645e7ba7fc421';
public const PACKAGE_VERSION = '0.15.23';
/**
* @api
* @var string
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit6557d86d25b72b29ae6a1db2d469e8bf::getLoader();
return ComposerAutoloaderInit9f6e7df67f84d69f5769d46267ba7660::getLoader();
10 changes: 5 additions & 5 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit6557d86d25b72b29ae6a1db2d469e8bf
class ComposerAutoloaderInit9f6e7df67f84d69f5769d46267ba7660
{
private static $loader;

Expand All @@ -22,17 +22,17 @@ public static function getLoader()
return self::$loader;
}

spl_autoload_register(array('ComposerAutoloaderInit6557d86d25b72b29ae6a1db2d469e8bf', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit9f6e7df67f84d69f5769d46267ba7660', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit6557d86d25b72b29ae6a1db2d469e8bf', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit9f6e7df67f84d69f5769d46267ba7660', 'loadClassLoader'));

require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit6557d86d25b72b29ae6a1db2d469e8bf::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit9f6e7df67f84d69f5769d46267ba7660::getInitializer($loader));

$loader->setClassMapAuthoritative(true);
$loader->register(true);

$filesToLoad = \Composer\Autoload\ComposerStaticInit6557d86d25b72b29ae6a1db2d469e8bf::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit9f6e7df67f84d69f5769d46267ba7660::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInit6557d86d25b72b29ae6a1db2d469e8bf
class ComposerStaticInit9f6e7df67f84d69f5769d46267ba7660
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
Expand Down Expand Up @@ -3127,9 +3127,9 @@ class ComposerStaticInit6557d86d25b72b29ae6a1db2d469e8bf
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit6557d86d25b72b29ae6a1db2d469e8bf::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6557d86d25b72b29ae6a1db2d469e8bf::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit6557d86d25b72b29ae6a1db2d469e8bf::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit9f6e7df67f84d69f5769d46267ba7660::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit9f6e7df67f84d69f5769d46267ba7660::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit9f6e7df67f84d69f5769d46267ba7660::$classMap;

}, null, ClassLoader::class);
}
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -1989,12 +1989,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-downgrade-php.git",
"reference": "b7d84923a099e4cf8cba027dcb447580e345d3e3"
"reference": "84309d3d673943808e680a5004bdd9f8ba67e605"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/b7d84923a099e4cf8cba027dcb447580e345d3e3",
"reference": "b7d84923a099e4cf8cba027dcb447580e345d3e3",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-downgrade-php\/zipball\/84309d3d673943808e680a5004bdd9f8ba67e605",
"reference": "84309d3d673943808e680a5004bdd9f8ba67e605",
"shasum": ""
},
"require": {
Expand All @@ -2018,7 +2018,7 @@
"tomasvotruba\/type-coverage": "^0.0.9",
"tomasvotruba\/unused-public": "^0.0.34"
},
"time": "2023-03-09T13:49:24+00:00",
"time": "2023-03-22T15:15:52+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
Expand Down
2 changes: 1 addition & 1 deletion vendor/composer/installed.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vendor/rector/extension-installer/src/GeneratedConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
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 5fe59e9'), '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 b7d8492'), '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 dfeb67c'), '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 e43a11e'));
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 5fe59e9'), '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 84309d3'), '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 dfeb67c'), '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 e43a11e'));
private function __construct()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@

use PhpParser\Node;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\ClassConst;
use PhpParser\Node\Stmt\ClassLike;
use PHPStan\Analyser\MutatingScope;
use PHPStan\Analyser\Scope;
use Rector\Core\PhpParser\AstResolver;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\DowngradePhp81\NodeAnalyzer\ArraySpreadAnalyzer;
use Rector\DowngradePhp81\NodeFactory\ArrayMergeFromArraySpreadFactory;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
Expand All @@ -29,10 +38,16 @@ final class DowngradeArraySpreadRector extends AbstractScopeAwareRector
* @var \Rector\DowngradePhp81\NodeAnalyzer\ArraySpreadAnalyzer
*/
private $arraySpreadAnalyzer;
public function __construct(ArrayMergeFromArraySpreadFactory $arrayMergeFromArraySpreadFactory, ArraySpreadAnalyzer $arraySpreadAnalyzer)
/**
* @readonly
* @var \Rector\Core\PhpParser\AstResolver
*/
private $astResolver;
public function __construct(ArrayMergeFromArraySpreadFactory $arrayMergeFromArraySpreadFactory, ArraySpreadAnalyzer $arraySpreadAnalyzer, AstResolver $astResolver)
{
$this->arrayMergeFromArraySpreadFactory = $arrayMergeFromArraySpreadFactory;
$this->arraySpreadAnalyzer = $arraySpreadAnalyzer;
$this->astResolver = $astResolver;
}
public function getRuleDefinition() : RuleDefinition
{
Expand Down Expand Up @@ -84,6 +99,13 @@ public function refactorWithScope(Node $node, Scope $scope) : ?Node
if (!$this->arraySpreadAnalyzer->isArrayWithUnpack($node)) {
return null;
}
$classConst = $this->betterNodeFinder->findParentType($node, ClassConst::class);
if ($classConst instanceof ClassConst) {
$refactorUnderClassConst = $this->refactorUnderClassConst($node, $classConst);
if ($refactorUnderClassConst instanceof Array_) {
return $refactorUnderClassConst;
}
}
$shouldIncrement = (bool) $this->betterNodeFinder->findFirstNext($node, function (Node $subNode) : bool {
if (!$subNode instanceof Array_) {
return \false;
Expand All @@ -93,4 +115,37 @@ public function refactorWithScope(Node $node, Scope $scope) : ?Node
/** @var MutatingScope $scope */
return $this->arrayMergeFromArraySpreadFactory->createFromArray($node, $scope, $this->file, $shouldIncrement);
}
private function refactorUnderClassConst(Array_ $array, ClassConst $classConst) : ?Array_
{
$node = $classConst->getAttribute(AttributeKey::PARENT_NODE);
$hasChanged = \false;
if (!$node instanceof ClassLike) {
return null;
}
foreach ($array->items as $key => $item) {
if ($item instanceof ArrayItem && $item->unpack && $item->value instanceof ClassConstFetch && $item->value->class instanceof Name) {
$type = $this->nodeTypeResolver->getType($item->value->class);
$name = $item->value->name;
if ($type instanceof FullyQualifiedObjectType && $name instanceof Identifier) {
$classLike = $this->astResolver->resolveClassFromName($type->getClassName());
if (!$classLike instanceof ClassLike) {
continue;
}
$constants = $classLike->getConstants();
foreach ($constants as $constant) {
$const = $constant->consts[0];
if ($const->name instanceof Identifier && $const->name->toString() === $name->toString() && $const->value instanceof Array_) {
unset($array->items[$key]);
\array_splice($array->items, $key, 0, $const->value->items);
$hasChanged = \true;
}
}
}
}
}
if ($hasChanged) {
return $array;
}
return null;
}
}

0 comments on commit f4984eb

Please sign in to comment.