Updated Rector to commit 07a7876d8a4c93097c966730acbc4aeb7d9e1765

07a7876d8a [CodingStyle] Remove OrderAttributesRector, as rather coding standard and does not have specific PSR example (#3838)
This commit is contained in:
Tomas Votruba 2023-05-14 13:22:44 +00:00
parent b381887836
commit 33a05b3e73
18 changed files with 18 additions and 232 deletions

View File

@ -1,4 +1,4 @@
# 411 Rules Overview
# 410 Rules Overview
<br>
@ -8,7 +8,7 @@
- [CodeQuality](#codequality) (76)
- [CodingStyle](#codingstyle) (36)
- [CodingStyle](#codingstyle) (35)
- [Compatibility](#compatibility) (1)
@ -2174,71 +2174,6 @@ Changes already typed Type|null to ?Type
<br>
### OrderAttributesRector
Order attributes by desired names
:wrench: **configure it!**
- class: [`Rector\CodingStyle\Rector\ClassMethod\OrderAttributesRector`](../rules/CodingStyle/Rector/ClassMethod/OrderAttributesRector.php)
```php
<?php
declare(strict_types=1);
use Rector\CodingStyle\Rector\ClassMethod\OrderAttributesRector;
use Rector\Config\RectorConfig;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(OrderAttributesRector::class, [
'First',
'Second',
]);
};
```
```diff
+#[First]
#[Second]
-#[First]
class Someclass
{
}
```
<br>
```php
<?php
declare(strict_types=1);
use Rector\CodingStyle\Rector\ClassMethod\OrderAttributesRector;
use Rector\Config\RectorConfig;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(OrderAttributesRector::class, [
'alphabetically',
]);
};
```
```diff
+#[AAttribute]
#[BAttribute]
-#[AAttribute]
class Someclass
{
}
```
<br>
### PostIncDecToPreIncDecRector
Use ++$value or --$value instead of `$value++` or `$value--`

View File

@ -10,8 +10,8 @@ use PhpParser\Node\Stmt\Return_;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitorAbstract;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
final class ByRefReturnNodeVisitor extends NodeVisitorAbstract implements ScopeResolverNodeVisitorInterface
{
/**

View File

@ -10,8 +10,8 @@ use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
use PhpParser\NodeVisitorAbstract;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
final class ByRefVariableNodeVisitor extends NodeVisitorAbstract implements ScopeResolverNodeVisitorInterface
{
/**

View File

@ -12,8 +12,8 @@ use PhpParser\NodeTraverser;
use PhpParser\NodeVisitorAbstract;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
final class GlobalVariableNodeVisitor extends NodeVisitorAbstract implements ScopeResolverNodeVisitorInterface
{
/**

View File

@ -12,8 +12,8 @@ use PhpParser\NodeTraverser;
use PhpParser\NodeVisitorAbstract;
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
final class StaticVariableNodeVisitor extends NodeVisitorAbstract implements ScopeResolverNodeVisitorInterface
{
/**

View File

@ -9,7 +9,6 @@ use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use PHPStan\Analyser\Scope;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\DeadCode\SideEffect\SideEffectNodeDetector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;

View File

@ -1,140 +0,0 @@
<?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 RectorPrefix202305\Webmozart\Assert\Assert;
/**
* @see \Rector\Tests\CodingStyle\Rector\ClassMethod\OrderAttributesRector\SpecificOrder\SpecificOrderAttributesRectorTest
*/
final class OrderAttributesRector extends AbstractRector implements ConfigurableRectorInterface
{
/**
* @api
* @var string
*/
public const ALPHABETICALLY = 'alphabetically';
/**
* @var array<string, int>|array<string>
*/
private $configuration = [];
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Order attributes by desired names', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
#[Second]
#[First]
class Someclass
{
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
#[First]
#[Second]
class Someclass
{
}
CODE_SAMPLE
, ['First', 'Second']), new ConfiguredCodeSample(<<<'CODE_SAMPLE'
#[BAttribute]
#[AAttribute]
class Someclass
{
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
#[AAttribute]
#[BAttribute]
class Someclass
{
}
CODE_SAMPLE
, [self::ALPHABETICALLY])]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Class_::class, Property::class, Param::class, ClassMethod::class, Function_::class, Closure::class, ArrowFunction::class];
}
/**
* @param ClassMethod|Property|Function_|Closure|Param|Class_|ArrowFunction $node
*/
public function refactor(Node $node) : ?Node
{
if ($node->attrGroups === []) {
return null;
}
$originalAttrGroups = $node->attrGroups;
if ($this->isAlphabetically($this->configuration)) {
$currentAttrGroups = $this->sortAlphabetically($originalAttrGroups);
} else {
$currentAttrGroups = $this->sortBySpecificOrder($originalAttrGroups);
}
if ($currentAttrGroups === $originalAttrGroups) {
return null;
}
$node->attrGroups = $currentAttrGroups;
return $node;
}
/**
* @param mixed[] $configuration
*/
public function configure(array $configuration = [self::ALPHABETICALLY]) : void
{
Assert::allString($configuration);
Assert::minCount($configuration, 1);
$this->configuration = $this->isAlphabetically($configuration) ? $configuration : \array_flip($configuration);
}
/**
* @param array<AttributeGroup> $originalAttrGroups
* @return array<AttributeGroup>
*/
private function sortAlphabetically(array $originalAttrGroups) : array
{
\usort($originalAttrGroups, function (AttributeGroup $firstAttributeGroup, AttributeGroup $secondAttributeGroup) : int {
$currentNamespace = $this->getName($firstAttributeGroup->attrs[0]->name);
$nextNamespace = $this->getName($secondAttributeGroup->attrs[0]->name);
return \strcmp($currentNamespace, $nextNamespace);
});
return $originalAttrGroups;
}
/**
* @param array<AttributeGroup> $originalAttrGroups
* @return array<AttributeGroup>
*/
private function sortBySpecificOrder(array $originalAttrGroups) : array
{
\usort($originalAttrGroups, function (AttributeGroup $firstAttributeGroup, AttributeGroup $secondAttributeGroup) : int {
$firstAttributePosition = $this->resolveAttributeGroupPosition($firstAttributeGroup);
$secondAttributePosition = $this->resolveAttributeGroupPosition($secondAttributeGroup);
return $firstAttributePosition <=> $secondAttributePosition;
});
return $originalAttrGroups;
}
private function resolveAttributeGroupPosition(AttributeGroup $attributeGroup) : int
{
$attrName = $this->getName($attributeGroup->attrs[0]->name);
return (int) ($this->configuration[$attrName] ?? \count($this->configuration));
}
/**
* @param array<string, int>|array<string> $configuration
*/
private function isAlphabetically(array $configuration) : bool
{
return \count($configuration) === 1 && $configuration[0] === self::ALPHABETICALLY;
}
}

View File

@ -17,7 +17,6 @@ use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Namespace_;
use PHPStan\Analyser\Scope;
use Rector\Core\PhpParser\Node\CustomNode\FileWithoutNamespace;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\DeadCode\SideEffect\SideEffectNodeDetector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;

View File

@ -10,7 +10,6 @@ use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;
use Rector\Core\NodeManipulator\PropertyManipulator;
use Rector\Core\PhpParser\NodeFinder\PropertyFetchFinder;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Core\ValueObject\MethodName;
use Rector\Core\ValueObject\PhpVersionFeature;

View File

@ -10,7 +10,6 @@ use PhpParser\Node\Stmt\Property;
use PHPStan\Analyser\Scope;
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
use Rector\Core\NodeManipulator\PropertyManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Removing\NodeManipulator\ComplexNodeRemover;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;

View File

@ -9,7 +9,6 @@ use PHPStan\Analyser\Scope;
use PHPStan\Reflection\Native\NativeFunctionReflection;
use PHPStan\Reflection\ReflectionProvider;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
final class PureFunctionDetector
{
/**

View File

@ -18,7 +18,6 @@ use PHPStan\Analyser\Scope;
use Rector\Core\NodeAnalyzer\ParamAnalyzer;
use Rector\Core\NodeManipulator\PropertyFetchAssignManipulator;
use Rector\Core\NodeManipulator\PropertyManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Core\ValueObject\MethodName;
use Rector\Core\ValueObject\PhpVersionFeature;

View File

@ -11,7 +11,6 @@ use PhpParser\Node\Stmt\PropertyProperty;
use PHPStan\Analyser\Scope;
use PHPStan\Type\ObjectType;
use Rector\Core\NodeManipulator\PropertyManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Rector\AbstractScopeAwareRector;
use Rector\Privatization\NodeFactory\ClassConstantFactory;
use Rector\Privatization\NodeReplacer\PropertyFetchWithConstFetchReplacer;

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'ad7012054f92137311b202c0322a62dd480fe3bb';
public const PACKAGE_VERSION = '07a7876d8a4c93097c966730acbc4aeb7d9e1765';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-05-14 11:50:21';
public const RELEASE_DATE = '2023-05-14 13:18:13';
/**
* @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 ComposerAutoloaderInit4d9f8fb9fb75236959043efa31872d63::getLoader();
return ComposerAutoloaderInite3e6ce2ce5c729544623b21247060b5e::getLoader();

View File

@ -1324,7 +1324,6 @@ 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\\ReturnArrayClassMethodToYieldRector' => $baseDir . '/rules/CodingStyle/Rector/ClassMethod/ReturnArrayClassMethodToYieldRector.php',
'Rector\\CodingStyle\\Rector\\ClassMethod\\UnSpreadOperatorRector' => $baseDir . '/rules/CodingStyle/Rector/ClassMethod/UnSpreadOperatorRector.php',
'Rector\\CodingStyle\\Rector\\Class_\\AddArrayDefaultToArrayPropertyRector' => $baseDir . '/rules/CodingStyle/Rector/Class_/AddArrayDefaultToArrayPropertyRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit4d9f8fb9fb75236959043efa31872d63
class ComposerAutoloaderInite3e6ce2ce5c729544623b21247060b5e
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit4d9f8fb9fb75236959043efa31872d63
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit4d9f8fb9fb75236959043efa31872d63', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInite3e6ce2ce5c729544623b21247060b5e', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit4d9f8fb9fb75236959043efa31872d63', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInite3e6ce2ce5c729544623b21247060b5e', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit4d9f8fb9fb75236959043efa31872d63::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInite3e6ce2ce5c729544623b21247060b5e::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit4d9f8fb9fb75236959043efa31872d63::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInite3e6ce2ce5c729544623b21247060b5e::$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 ComposerStaticInit4d9f8fb9fb75236959043efa31872d63
class ComposerStaticInite3e6ce2ce5c729544623b21247060b5e
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -1566,7 +1566,6 @@ class ComposerStaticInit4d9f8fb9fb75236959043efa31872d63
'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\\ReturnArrayClassMethodToYieldRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ClassMethod/ReturnArrayClassMethodToYieldRector.php',
'Rector\\CodingStyle\\Rector\\ClassMethod\\UnSpreadOperatorRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/ClassMethod/UnSpreadOperatorRector.php',
'Rector\\CodingStyle\\Rector\\Class_\\AddArrayDefaultToArrayPropertyRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/Class_/AddArrayDefaultToArrayPropertyRector.php',
@ -3112,9 +3111,9 @@ class ComposerStaticInit4d9f8fb9fb75236959043efa31872d63
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit4d9f8fb9fb75236959043efa31872d63::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit4d9f8fb9fb75236959043efa31872d63::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit4d9f8fb9fb75236959043efa31872d63::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInite3e6ce2ce5c729544623b21247060b5e::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInite3e6ce2ce5c729544623b21247060b5e::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInite3e6ce2ce5c729544623b21247060b5e::$classMap;
}, null, ClassLoader::class);
}