mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-31 16:30:51 +00:00
Updated Rector to commit bb41d72116
bb41d72116
[CodingStyle] Add OrderAttributesRector (#459)
This commit is contained in:
parent
0ead874fad
commit
767752c16e
|
@ -0,0 +1,92 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\CodingStyle\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\AttributeGroup;
|
||||
use PhpParser\Node\Expr\ArrowFunction;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
use RectorPrefix20210719\Webmozart\Assert\Assert;
|
||||
/**
|
||||
* @see \Rector\Tests\CodingStyle\Rector\ClassMethod\OrderAttributesRector\OrderAttributesRectorTest
|
||||
*/
|
||||
final class OrderAttributesRector extends \Rector\Core\Rector\AbstractRector implements \Rector\Core\Contract\Rector\ConfigurableRectorInterface
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const ATTRIBUTES_ORDER = 'attributes_order';
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private $attributesOrder = [];
|
||||
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'
|
||||
#[Second]
|
||||
#[First]
|
||||
class Someclass
|
||||
{
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
#[First]
|
||||
#[Second]
|
||||
class Someclass
|
||||
{
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, [self::ATTRIBUTES_ORDER => ['First', 'Second']])]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [\PhpParser\Node\Stmt\Class_::class, \PhpParser\Node\Stmt\Property::class, \PhpParser\Node\Param::class, \PhpParser\Node\Stmt\ClassMethod::class, \PhpParser\Node\Stmt\Function_::class, \PhpParser\Node\Expr\Closure::class, \PhpParser\Node\Expr\ArrowFunction::class];
|
||||
}
|
||||
/**
|
||||
* @param ClassMethod|Property|Function_|Closure|Param|Class_|ArrowFunction $node
|
||||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
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;
|
||||
return $firstAttributePosition <=> $secondAttributePosition;
|
||||
});
|
||||
if ($currentAttrGroups === $originalAttrGroups) {
|
||||
return null;
|
||||
}
|
||||
$node->attrGroups = $currentAttrGroups;
|
||||
return $node;
|
||||
}
|
||||
/**
|
||||
* @param array<string, mixed> $configuration
|
||||
*/
|
||||
public function configure(array $configuration) : void
|
||||
{
|
||||
$attributesOrder = $configuration[self::ATTRIBUTES_ORDER] ?? [];
|
||||
\RectorPrefix20210719\Webmozart\Assert\Assert::allString($attributesOrder);
|
||||
$this->attributesOrder = $attributesOrder;
|
||||
}
|
||||
}
|
|
@ -12,7 +12,6 @@ use PhpParser\Node\Stmt\ClassMethod;
|
|||
use PhpParser\Node\Stmt\Function_;
|
||||
use PhpParser\Node\UnionType as PhpParserUnionType;
|
||||
use PHPStan\Type\MixedType;
|
||||
use PHPStan\Type\ThisType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\UnionType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
|
|
|
@ -75,10 +75,6 @@ final class ReturnTypeInferer
|
|||
}
|
||||
return new \PHPStan\Type\MixedType();
|
||||
}
|
||||
private function isStaticType(\PHPStan\Type\Type $type) : bool
|
||||
{
|
||||
return $type instanceof \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType && $type->getClassName() === 'static';
|
||||
}
|
||||
public function verifyStaticType(\PHPStan\Type\Type $type, bool $isSupportedStaticReturnType) : ?\PHPStan\Type\Type
|
||||
{
|
||||
if ($this->isStaticType($type)) {
|
||||
|
@ -111,6 +107,10 @@ final class ReturnTypeInferer
|
|||
}
|
||||
return new \PHPStan\Type\UnionType($types);
|
||||
}
|
||||
private function isStaticType(\PHPStan\Type\Type $type) : bool
|
||||
{
|
||||
return $type instanceof \Rector\StaticTypeMapper\ValueObject\Type\FullyQualifiedObjectType && $type->getClassName() === 'static';
|
||||
}
|
||||
/**
|
||||
* @param array<class-string<ReturnTypeInfererInterface>> $excludedInferers
|
||||
*/
|
||||
|
|
|
@ -16,11 +16,11 @@ final class VersionResolver
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '75c06eab69f50725add0c315bc6dfaf4a7b2f5c5';
|
||||
public const PACKAGE_VERSION = 'bb41d721161826eb0fc18373b1ec99cd2e01a25d';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2021-07-19 06:57:26';
|
||||
public const RELEASE_DATE = '2021-07-19 08:24:11';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20210719\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -4,4 +4,4 @@
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit904e02de3962dfcb7ec769ef3bc13d8c::getLoader();
|
||||
return ComposerAutoloaderInit37f8d5a7ba1c21ff17f8f75ac79c08ae::getLoader();
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -1717,6 +1717,7 @@ return array(
|
|||
'Rector\\CodingStyle\\Rector\\ClassMethod\\FuncGetArgsToVariadicParamRector' => $baseDir . '/rules/CodingStyle/Rector/ClassMethod/FuncGetArgsToVariadicParamRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\ClassMethod\\MakeInheritedMethodVisibilitySameAsParentRector' => $baseDir . '/rules/CodingStyle/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\ClassMethod\\NewlineBeforeNewAssignSetRector' => $baseDir . '/rules/CodingStyle/Rector/ClassMethod/NewlineBeforeNewAssignSetRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\ClassMethod\\OrderAttributesRector' => $baseDir . '/rules/CodingStyle/Rector/ClassMethod/OrderAttributesRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\ClassMethod\\RemoveDoubleUnderscoreInMethodNameRector' => $baseDir . '/rules/CodingStyle/Rector/ClassMethod/RemoveDoubleUnderscoreInMethodNameRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\ClassMethod\\ReturnArrayClassMethodToYieldRector' => $baseDir . '/rules/CodingStyle/Rector/ClassMethod/ReturnArrayClassMethodToYieldRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\ClassMethod\\UnSpreadOperatorRector' => $baseDir . '/rules/CodingStyle/Rector/ClassMethod/UnSpreadOperatorRector.php',
|
||||
|
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit904e02de3962dfcb7ec769ef3bc13d8c
|
||||
class ComposerAutoloaderInit37f8d5a7ba1c21ff17f8f75ac79c08ae
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,15 +22,15 @@ class ComposerAutoloaderInit904e02de3962dfcb7ec769ef3bc13d8c
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit904e02de3962dfcb7ec769ef3bc13d8c', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit37f8d5a7ba1c21ff17f8f75ac79c08ae', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit904e02de3962dfcb7ec769ef3bc13d8c', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit37f8d5a7ba1c21ff17f8f75ac79c08ae', '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\ComposerStaticInit904e02de3962dfcb7ec769ef3bc13d8c::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit37f8d5a7ba1c21ff17f8f75ac79c08ae::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
|
@ -42,19 +42,19 @@ class ComposerAutoloaderInit904e02de3962dfcb7ec769ef3bc13d8c
|
|||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit904e02de3962dfcb7ec769ef3bc13d8c::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit37f8d5a7ba1c21ff17f8f75ac79c08ae::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire904e02de3962dfcb7ec769ef3bc13d8c($fileIdentifier, $file);
|
||||
composerRequire37f8d5a7ba1c21ff17f8f75ac79c08ae($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequire904e02de3962dfcb7ec769ef3bc13d8c($fileIdentifier, $file)
|
||||
function composerRequire37f8d5a7ba1c21ff17f8f75ac79c08ae($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit904e02de3962dfcb7ec769ef3bc13d8c
|
||||
class ComposerStaticInit37f8d5a7ba1c21ff17f8f75ac79c08ae
|
||||
{
|
||||
public static $files = array (
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||
|
@ -2072,6 +2072,7 @@ class ComposerStaticInit904e02de3962dfcb7ec769ef3bc13d8c
|
|||
'Rector\\CodingStyle\\Rector\\ClassMethod\\FuncGetArgsToVariadicParamRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ClassMethod/FuncGetArgsToVariadicParamRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\ClassMethod\\MakeInheritedMethodVisibilitySameAsParentRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ClassMethod/MakeInheritedMethodVisibilitySameAsParentRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\ClassMethod\\NewlineBeforeNewAssignSetRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ClassMethod/NewlineBeforeNewAssignSetRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\ClassMethod\\OrderAttributesRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ClassMethod/OrderAttributesRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\ClassMethod\\RemoveDoubleUnderscoreInMethodNameRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ClassMethod/RemoveDoubleUnderscoreInMethodNameRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\ClassMethod\\ReturnArrayClassMethodToYieldRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ClassMethod/ReturnArrayClassMethodToYieldRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\ClassMethod\\UnSpreadOperatorRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ClassMethod/UnSpreadOperatorRector.php',
|
||||
|
@ -3838,9 +3839,9 @@ class ComposerStaticInit904e02de3962dfcb7ec769ef3bc13d8c
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit904e02de3962dfcb7ec769ef3bc13d8c::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit904e02de3962dfcb7ec769ef3bc13d8c::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit904e02de3962dfcb7ec769ef3bc13d8c::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit37f8d5a7ba1c21ff17f8f75ac79c08ae::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit37f8d5a7ba1c21ff17f8f75ac79c08ae::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit37f8d5a7ba1c21ff17f8f75ac79c08ae::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
2
vendor/composer/installed.php
vendored
2
vendor/composer/installed.php
vendored
File diff suppressed because one or more lines are too long
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
|
@ -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('ComposerAutoloaderInit904e02de3962dfcb7ec769ef3bc13d8c', false) && !interface_exists('ComposerAutoloaderInit904e02de3962dfcb7ec769ef3bc13d8c', false) && !trait_exists('ComposerAutoloaderInit904e02de3962dfcb7ec769ef3bc13d8c', false)) {
|
||||
spl_autoload_call('RectorPrefix20210719\ComposerAutoloaderInit904e02de3962dfcb7ec769ef3bc13d8c');
|
||||
if (!class_exists('ComposerAutoloaderInit37f8d5a7ba1c21ff17f8f75ac79c08ae', false) && !interface_exists('ComposerAutoloaderInit37f8d5a7ba1c21ff17f8f75ac79c08ae', false) && !trait_exists('ComposerAutoloaderInit37f8d5a7ba1c21ff17f8f75ac79c08ae', false)) {
|
||||
spl_autoload_call('RectorPrefix20210719\ComposerAutoloaderInit37f8d5a7ba1c21ff17f8f75ac79c08ae');
|
||||
}
|
||||
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('composerRequire904e02de3962dfcb7ec769ef3bc13d8c')) {
|
||||
function composerRequire904e02de3962dfcb7ec769ef3bc13d8c() {
|
||||
return \RectorPrefix20210719\composerRequire904e02de3962dfcb7ec769ef3bc13d8c(...func_get_args());
|
||||
if (!function_exists('composerRequire37f8d5a7ba1c21ff17f8f75ac79c08ae')) {
|
||||
function composerRequire37f8d5a7ba1c21ff17f8f75ac79c08ae() {
|
||||
return \RectorPrefix20210719\composerRequire37f8d5a7ba1c21ff17f8f75ac79c08ae(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('parseArgs')) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user