Updated Rector to commit 9da4597c9a6d76d8c0d83ec13410a9d479526b71

9da4597c9a Improve attribute order rule (#460)
This commit is contained in:
Tomas Votruba 2021-07-19 09:21:13 +00:00
parent 550e40fa60
commit 1c8f0de25b
6 changed files with 31 additions and 29 deletions

View File

@ -27,9 +27,9 @@ final class OrderAttributesRector extends \Rector\Core\Rector\AbstractRector imp
*/
public const ATTRIBUTES_ORDER = 'attributes_order';
/**
* @var string[]
* @var array<string, int>
*/
private $attributesOrder = [];
private $attributesOrderByName = [];
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Order attributes by desired names', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample(<<<'CODE_SAMPLE'
@ -63,15 +63,11 @@ CODE_SAMPLE
if ($node->attrGroups === []) {
return null;
}
$attributesOrderByName = \array_flip($this->attributesOrder);
$originalAttrGroups = $node->attrGroups;
$currentAttrGroups = $originalAttrGroups;
\usort($currentAttrGroups, function (\PhpParser\Node\AttributeGroup $firstAttributeGroup, \PhpParser\Node\AttributeGroup $secondAttributeGroup) use($attributesOrderByName) : int {
$firstAttrName = $this->getName($firstAttributeGroup->attrs[0]->name);
$secondAttrName = $this->getName($secondAttributeGroup->attrs[0]->name);
// 1000 makes the attribute last, as positioned attributes have a priority
$firstAttributePosition = $attributesOrderByName[$firstAttrName] ?? 1000;
$secondAttributePosition = $attributesOrderByName[$secondAttrName] ?? 1000;
\usort($currentAttrGroups, function (\PhpParser\Node\AttributeGroup $firstAttributeGroup, \PhpParser\Node\AttributeGroup $secondAttributeGroup) : int {
$firstAttributePosition = $this->resolveAttributeGroupPosition($firstAttributeGroup);
$secondAttributePosition = $this->resolveAttributeGroupPosition($secondAttributeGroup);
return $firstAttributePosition <=> $secondAttributePosition;
});
if ($currentAttrGroups === $originalAttrGroups) {
@ -87,6 +83,12 @@ CODE_SAMPLE
{
$attributesOrder = $configuration[self::ATTRIBUTES_ORDER] ?? [];
\RectorPrefix20210719\Webmozart\Assert\Assert::allString($attributesOrder);
$this->attributesOrder = $attributesOrder;
$this->attributesOrderByName = \array_flip($attributesOrder);
}
private function resolveAttributeGroupPosition(\PhpParser\Node\AttributeGroup $attributeGroup) : int
{
$attrName = $this->getName($attributeGroup->attrs[0]->name);
// 1000 makes the attribute last, as positioned attributes have a higher priority
return $this->attributesOrderByName[$attrName] ?? 1000;
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '1c76f252599680d1ea8d3cd934c0a47a0cdfcbb0';
public const PACKAGE_VERSION = '9da4597c9a6d76d8c0d83ec13410a9d479526b71';
/**
* @var string
*/
public const RELEASE_DATE = '2021-07-19 14:56:42';
public const RELEASE_DATE = '2021-07-19 09:10:13';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20210719\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit02e8a54708336a15d0794a2b94d910b7::getLoader();
return ComposerAutoloaderInit401cdfcab2dd44ed81387042c35a6cbb::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit02e8a54708336a15d0794a2b94d910b7
class ComposerAutoloaderInit401cdfcab2dd44ed81387042c35a6cbb
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInit02e8a54708336a15d0794a2b94d910b7
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit02e8a54708336a15d0794a2b94d910b7', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit401cdfcab2dd44ed81387042c35a6cbb', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit02e8a54708336a15d0794a2b94d910b7', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit401cdfcab2dd44ed81387042c35a6cbb', '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\ComposerStaticInit02e8a54708336a15d0794a2b94d910b7::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit401cdfcab2dd44ed81387042c35a6cbb::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,19 +42,19 @@ class ComposerAutoloaderInit02e8a54708336a15d0794a2b94d910b7
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit02e8a54708336a15d0794a2b94d910b7::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit401cdfcab2dd44ed81387042c35a6cbb::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire02e8a54708336a15d0794a2b94d910b7($fileIdentifier, $file);
composerRequire401cdfcab2dd44ed81387042c35a6cbb($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequire02e8a54708336a15d0794a2b94d910b7($fileIdentifier, $file)
function composerRequire401cdfcab2dd44ed81387042c35a6cbb($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit02e8a54708336a15d0794a2b94d910b7
class ComposerStaticInit401cdfcab2dd44ed81387042c35a6cbb
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -3839,9 +3839,9 @@ class ComposerStaticInit02e8a54708336a15d0794a2b94d910b7
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit02e8a54708336a15d0794a2b94d910b7::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit02e8a54708336a15d0794a2b94d910b7::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit02e8a54708336a15d0794a2b94d910b7::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit401cdfcab2dd44ed81387042c35a6cbb::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit401cdfcab2dd44ed81387042c35a6cbb::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit401cdfcab2dd44ed81387042c35a6cbb::$classMap;
}, null, ClassLoader::class);
}

View File

@ -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('RectorPrefix20210719\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit02e8a54708336a15d0794a2b94d910b7', false) && !interface_exists('ComposerAutoloaderInit02e8a54708336a15d0794a2b94d910b7', false) && !trait_exists('ComposerAutoloaderInit02e8a54708336a15d0794a2b94d910b7', false)) {
spl_autoload_call('RectorPrefix20210719\ComposerAutoloaderInit02e8a54708336a15d0794a2b94d910b7');
if (!class_exists('ComposerAutoloaderInit401cdfcab2dd44ed81387042c35a6cbb', false) && !interface_exists('ComposerAutoloaderInit401cdfcab2dd44ed81387042c35a6cbb', false) && !trait_exists('ComposerAutoloaderInit401cdfcab2dd44ed81387042c35a6cbb', false)) {
spl_autoload_call('RectorPrefix20210719\ComposerAutoloaderInit401cdfcab2dd44ed81387042c35a6cbb');
}
if (!class_exists('Doctrine\Inflector\Inflector', false) && !interface_exists('Doctrine\Inflector\Inflector', false) && !trait_exists('Doctrine\Inflector\Inflector', false)) {
spl_autoload_call('RectorPrefix20210719\Doctrine\Inflector\Inflector');
@ -3308,9 +3308,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20210719\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire02e8a54708336a15d0794a2b94d910b7')) {
function composerRequire02e8a54708336a15d0794a2b94d910b7() {
return \RectorPrefix20210719\composerRequire02e8a54708336a15d0794a2b94d910b7(...func_get_args());
if (!function_exists('composerRequire401cdfcab2dd44ed81387042c35a6cbb')) {
function composerRequire401cdfcab2dd44ed81387042c35a6cbb() {
return \RectorPrefix20210719\composerRequire401cdfcab2dd44ed81387042c35a6cbb(...func_get_args());
}
}
if (!function_exists('parseArgs')) {