mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-31 00:10:51 +00:00
Updated Rector to commit ae7648ed92396d39b4d364328312250b2c66f40e
ae7648ed92
[CodingStyle] Add StaticClosureRector (#2658)
This commit is contained in:
parent
2747e037dd
commit
9d2c3a2853
|
@ -15,6 +15,7 @@ use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsPar
|
|||
use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector;
|
||||
use Rector\CodingStyle\Rector\ClassMethod\RemoveDoubleUnderscoreInMethodNameRector;
|
||||
use Rector\CodingStyle\Rector\ClassMethod\UnSpreadOperatorRector;
|
||||
use Rector\CodingStyle\Rector\Closure\StaticClosureRector;
|
||||
use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
|
||||
use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
|
||||
use Rector\CodingStyle\Rector\FuncCall\CallUserFuncArrayToVariadicRector;
|
||||
|
@ -35,5 +36,5 @@ use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
|
|||
use Rector\Transform\Rector\FuncCall\FuncCallToConstFetchRector;
|
||||
return static function (RectorConfig $rectorConfig) : void {
|
||||
$rectorConfig->ruleWithConfiguration(FuncCallToConstFetchRector::class, ['php_sapi_name' => 'PHP_SAPI', 'pi' => 'M_PI']);
|
||||
$rectorConfig->rules([SeparateMultiUseImportsRector::class, RemoveDoubleUnderscoreInMethodNameRector::class, PostIncDecToPreIncDecRector::class, UnSpreadOperatorRector::class, NewlineAfterStatementRector::class, RemoveFinalFromConstRector::class, PHPStormVarAnnotationRector::class, NullableCompareToNullRector::class, BinarySwitchToIfElseRector::class, ConsistentImplodeRector::class, TernaryConditionVariableAssignmentRector::class, SymplifyQuoteEscapeRector::class, SplitGroupedConstantsAndPropertiesRector::class, StringClassNameToClassConstantRector::class, ConsistentPregDelimiterRector::class, CatchExceptionNameMatchingTypeRector::class, UseIncrementAssignRector::class, SplitDoubleAssignRector::class, VarConstantCommentRector::class, EncapsedStringsToSprintfRector::class, WrapEncapsedVariableInCurlyBracesRector::class, NewlineBeforeNewAssignSetRector::class, AddArrayDefaultToArrayPropertyRector::class, AddFalseDefaultToBoolPropertyRector::class, MakeInheritedMethodVisibilitySameAsParentRector::class, CallUserFuncArrayToVariadicRector::class, VersionCompareFuncCallToConstantRector::class, StaticArrowFunctionRector::class]);
|
||||
$rectorConfig->rules([SeparateMultiUseImportsRector::class, RemoveDoubleUnderscoreInMethodNameRector::class, PostIncDecToPreIncDecRector::class, UnSpreadOperatorRector::class, NewlineAfterStatementRector::class, RemoveFinalFromConstRector::class, PHPStormVarAnnotationRector::class, NullableCompareToNullRector::class, BinarySwitchToIfElseRector::class, ConsistentImplodeRector::class, TernaryConditionVariableAssignmentRector::class, SymplifyQuoteEscapeRector::class, SplitGroupedConstantsAndPropertiesRector::class, StringClassNameToClassConstantRector::class, ConsistentPregDelimiterRector::class, CatchExceptionNameMatchingTypeRector::class, UseIncrementAssignRector::class, SplitDoubleAssignRector::class, VarConstantCommentRector::class, EncapsedStringsToSprintfRector::class, WrapEncapsedVariableInCurlyBracesRector::class, NewlineBeforeNewAssignSetRector::class, AddArrayDefaultToArrayPropertyRector::class, AddFalseDefaultToBoolPropertyRector::class, MakeInheritedMethodVisibilitySameAsParentRector::class, CallUserFuncArrayToVariadicRector::class, VersionCompareFuncCallToConstantRector::class, StaticArrowFunctionRector::class, StaticClosureRector::class]);
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# 412 Rules Overview
|
||||
# 414 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
|||
|
||||
- [CodeQuality](#codequality) (73)
|
||||
|
||||
- [CodingStyle](#codingstyle) (35)
|
||||
- [CodingStyle](#codingstyle) (37)
|
||||
|
||||
- [Compatibility](#compatibility) (1)
|
||||
|
||||
|
@ -2339,6 +2339,38 @@ Separate constant and properties to own lines
|
|||
|
||||
<br>
|
||||
|
||||
### StaticArrowFunctionRector
|
||||
|
||||
Changes ArrowFunction to be static when possible
|
||||
|
||||
- class: [`Rector\CodingStyle\Rector\ArrowFunction\StaticArrowFunctionRector`](../rules/CodingStyle/Rector/ArrowFunction/StaticArrowFunctionRector.php)
|
||||
|
||||
```diff
|
||||
-fn (): string => 'test';
|
||||
+static fn (): string => 'test';
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### StaticClosureRector
|
||||
|
||||
Changes Closure to be static when possible
|
||||
|
||||
- class: [`Rector\CodingStyle\Rector\Closure\StaticClosureRector`](../rules/CodingStyle/Rector/Closure/StaticClosureRector.php)
|
||||
|
||||
```diff
|
||||
-function () {
|
||||
+static function () {
|
||||
if (rand(0, 1)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### StrictArraySearchRector
|
||||
|
||||
Makes array_search search for identical elements
|
||||
|
|
66
rules/CodingStyle/Rector/Closure/StaticClosureRector.php
Normal file
66
rules/CodingStyle/Rector/Closure/StaticClosureRector.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\CodingStyle\Rector\Closure;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Closure;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\CodingStyle\Rector\Closure\StaticClosureRector\StaticClosureRectorTest
|
||||
*/
|
||||
final class StaticClosureRector extends AbstractRector
|
||||
{
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Changes Closure to be static when possible', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
function () {
|
||||
if (rand(0, 1)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
static function () {
|
||||
if (rand(0, 1)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [Closure::class];
|
||||
}
|
||||
/**
|
||||
* @param Closure $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
if ($this->shouldSkip($node)) {
|
||||
return null;
|
||||
}
|
||||
$node->static = \true;
|
||||
return $node;
|
||||
}
|
||||
private function shouldSkip(Closure $closure) : bool
|
||||
{
|
||||
if ($closure->static) {
|
||||
return \true;
|
||||
}
|
||||
return (bool) $this->betterNodeFinder->findFirst($closure->stmts, static function (Node $subNode) : bool {
|
||||
return $subNode instanceof Variable && $subNode->name === 'this';
|
||||
});
|
||||
}
|
||||
}
|
|
@ -17,12 +17,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '743fef03d939a8a4fc4aa9364df057854e97e5c7';
|
||||
public const PACKAGE_VERSION = 'ae7648ed92396d39b4d364328312250b2c66f40e';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-07-13 23:01:38';
|
||||
public const RELEASE_DATE = '2022-07-14 03:30:00';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit4e1afc3d4f5d211b8221b9d2f71bd119::getLoader();
|
||||
return ComposerAutoloaderInit500eec63c392802592d1e38986bb5fdb::getLoader();
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -1441,6 +1441,7 @@ return array(
|
|||
'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',
|
||||
'Rector\\CodingStyle\\Rector\\Closure\\StaticClosureRector' => $baseDir . '/rules/CodingStyle/Rector/Closure/StaticClosureRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Encapsed\\EncapsedStringsToSprintfRector' => $baseDir . '/rules/CodingStyle/Rector/Encapsed/EncapsedStringsToSprintfRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Encapsed\\WrapEncapsedVariableInCurlyBracesRector' => $baseDir . '/rules/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\FuncCall\\CallUserFuncArrayToVariadicRector' => $baseDir . '/rules/CodingStyle/Rector/FuncCall/CallUserFuncArrayToVariadicRector.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 ComposerAutoloaderInit4e1afc3d4f5d211b8221b9d2f71bd119
|
||||
class ComposerAutoloaderInit500eec63c392802592d1e38986bb5fdb
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,19 +22,19 @@ class ComposerAutoloaderInit4e1afc3d4f5d211b8221b9d2f71bd119
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit4e1afc3d4f5d211b8221b9d2f71bd119', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit500eec63c392802592d1e38986bb5fdb', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit4e1afc3d4f5d211b8221b9d2f71bd119', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit500eec63c392802592d1e38986bb5fdb', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit4e1afc3d4f5d211b8221b9d2f71bd119::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit500eec63c392802592d1e38986bb5fdb::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit4e1afc3d4f5d211b8221b9d2f71bd119::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit500eec63c392802592d1e38986bb5fdb::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire4e1afc3d4f5d211b8221b9d2f71bd119($fileIdentifier, $file);
|
||||
composerRequire500eec63c392802592d1e38986bb5fdb($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
|
@ -46,7 +46,7 @@ class ComposerAutoloaderInit4e1afc3d4f5d211b8221b9d2f71bd119
|
|||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequire4e1afc3d4f5d211b8221b9d2f71bd119($fileIdentifier, $file)
|
||||
function composerRequire500eec63c392802592d1e38986bb5fdb($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit4e1afc3d4f5d211b8221b9d2f71bd119
|
||||
class ComposerStaticInit500eec63c392802592d1e38986bb5fdb
|
||||
{
|
||||
public static $files = array (
|
||||
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
|
||||
|
@ -1748,6 +1748,7 @@ class ComposerStaticInit4e1afc3d4f5d211b8221b9d2f71bd119
|
|||
'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',
|
||||
'Rector\\CodingStyle\\Rector\\Closure\\StaticClosureRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/Closure/StaticClosureRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Encapsed\\EncapsedStringsToSprintfRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/Encapsed/EncapsedStringsToSprintfRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\Encapsed\\WrapEncapsedVariableInCurlyBracesRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/Encapsed/WrapEncapsedVariableInCurlyBracesRector.php',
|
||||
'Rector\\CodingStyle\\Rector\\FuncCall\\CallUserFuncArrayToVariadicRector' => __DIR__ . '/../..' . '/rules/CodingStyle/Rector/FuncCall/CallUserFuncArrayToVariadicRector.php',
|
||||
|
@ -3415,9 +3416,9 @@ class ComposerStaticInit4e1afc3d4f5d211b8221b9d2f71bd119
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit4e1afc3d4f5d211b8221b9d2f71bd119::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit4e1afc3d4f5d211b8221b9d2f71bd119::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit4e1afc3d4f5d211b8221b9d2f71bd119::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit500eec63c392802592d1e38986bb5fdb::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit500eec63c392802592d1e38986bb5fdb::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit500eec63c392802592d1e38986bb5fdb::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user