mirror of
https://github.com/rectorphp/rector.git
synced 2024-05-28 23:10:51 +00:00
Updated Rector to commit de008767d91ad6cd5ed77bdc259454665e4bbde9
de008767d9
Replace static with self for private constants (#3178)
This commit is contained in:
parent
5c3e98d25a
commit
7924f6944c
|
@ -1,4 +1,4 @@
|
|||
# 411 Rules Overview
|
||||
# 412 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
|||
|
||||
- [Arguments](#arguments) (5)
|
||||
|
||||
- [CodeQuality](#codequality) (78)
|
||||
- [CodeQuality](#codequality) (79)
|
||||
|
||||
- [CodingStyle](#codingstyle) (38)
|
||||
|
||||
|
@ -594,6 +594,25 @@ Change multiple null compares to ?? queue
|
|||
|
||||
<br>
|
||||
|
||||
### ConvertStaticPrivateConstantToSelfRector
|
||||
|
||||
Replaces static::* access to private constants with self::* on final classes
|
||||
|
||||
- class: [`Rector\CodeQuality\Rector\ClassConstFetch\ConvertStaticPrivateConstantToSelfRector`](../rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php)
|
||||
|
||||
```diff
|
||||
final class Foo {
|
||||
private const BAR = 'bar';
|
||||
public function run()
|
||||
{
|
||||
- $bar = static::BAR;
|
||||
+ $bar = self::BAR;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### DoWhileBreakFalseToIfElseRector
|
||||
|
||||
Replace do (...} while (false); with more readable if/else conditions
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\CodeQuality\Rector\ClassConstFetch;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\ClassConstFetch;
|
||||
use PhpParser\Node\Name;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @see \Rector\Tests\CodeQuality\Rector\ClassConstFetch\ConvertStaticPrivateConstantToSelfRector\ConvertStaticPrivateConstantToSelfRectorTest
|
||||
* @see https://3v4l.org/8Y0ba
|
||||
* @see https://phpstan.org/r/11d4c850-1a40-4fae-b665-291f96104d11
|
||||
*/
|
||||
final class ConvertStaticPrivateConstantToSelfRector extends AbstractRector
|
||||
{
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
return new RuleDefinition('Replaces static::* access to private constants with self::* on final classes', [new CodeSample(<<<'CODE_SAMPLE'
|
||||
final class Foo {
|
||||
private const BAR = 'bar';
|
||||
public function run()
|
||||
{
|
||||
$bar = static::BAR;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
final class Foo {
|
||||
private const BAR = 'bar';
|
||||
public function run()
|
||||
{
|
||||
$bar = self::BAR;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [ClassConstFetch::class];
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Expr\ClassConstFetch $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?ClassConstFetch
|
||||
{
|
||||
if (!$this->isUsingStatic($node)) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isPrivateConstant($node)) {
|
||||
return null;
|
||||
}
|
||||
$node->class = new Name('self');
|
||||
return $node;
|
||||
}
|
||||
private function isUsingStatic(ClassConstFetch $node) : bool
|
||||
{
|
||||
if (!$node->class instanceof Name) {
|
||||
return \false;
|
||||
}
|
||||
return $node->class->toString() === 'static';
|
||||
}
|
||||
private function isPrivateConstant(ClassConstFetch $node) : bool
|
||||
{
|
||||
$class = $this->betterNodeFinder->findParentType($node, Node\Stmt\Class_::class);
|
||||
if (!$class instanceof Node\Stmt\Class_) {
|
||||
return \false;
|
||||
}
|
||||
if (!$class->isFinal()) {
|
||||
return \false;
|
||||
}
|
||||
$constantName = $node->name;
|
||||
if (!$constantName instanceof Node\Identifier) {
|
||||
return \false;
|
||||
}
|
||||
foreach ($class->getConstants() as $classConst) {
|
||||
if (!$this->nodeNameResolver->isName($classConst, $constantName->toString())) {
|
||||
continue;
|
||||
}
|
||||
return $classConst->isPrivate();
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
|
@ -17,12 +17,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'bea2e12a6d6e7a7b1eb1f7b6f82a0ec1e7c21f2c';
|
||||
public const PACKAGE_VERSION = 'de008767d91ad6cd5ed77bdc259454665e4bbde9';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-12-12 08:58:28';
|
||||
public const RELEASE_DATE = '2022-12-12 19:25:03';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitcaaf9e35911715a011b2dd61314f87c4::getLoader();
|
||||
return ComposerAutoloaderInit69ca48a6fd0e1398ed1e26f928726fec::getLoader();
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -1162,6 +1162,7 @@ return array(
|
|||
'Rector\\CodeQuality\\Rector\\BooleanNot\\ReplaceMultipleBooleanNotRector' => $baseDir . '/rules/CodeQuality/Rector/BooleanNot/ReplaceMultipleBooleanNotRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\BooleanNot\\SimplifyDeMorganBinaryRector' => $baseDir . '/rules/CodeQuality/Rector/BooleanNot/SimplifyDeMorganBinaryRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\Catch_\\ThrowWithPreviousExceptionRector' => $baseDir . '/rules/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\ClassConstFetch\\ConvertStaticPrivateConstantToSelfRector' => $baseDir . '/rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\ClassMethod\\InlineArrayReturnAssignRector' => $baseDir . '/rules/CodeQuality/Rector/ClassMethod/InlineArrayReturnAssignRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\ClassMethod\\NarrowUnionTypeDocRector' => $baseDir . '/rules/CodeQuality/Rector/ClassMethod/NarrowUnionTypeDocRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\ClassMethod\\OptionalParametersAfterRequiredRector' => $baseDir . '/rules/CodeQuality/Rector/ClassMethod/OptionalParametersAfterRequiredRector.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 ComposerAutoloaderInitcaaf9e35911715a011b2dd61314f87c4
|
||||
class ComposerAutoloaderInit69ca48a6fd0e1398ed1e26f928726fec
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,19 +22,19 @@ class ComposerAutoloaderInitcaaf9e35911715a011b2dd61314f87c4
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitcaaf9e35911715a011b2dd61314f87c4', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit69ca48a6fd0e1398ed1e26f928726fec', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitcaaf9e35911715a011b2dd61314f87c4', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit69ca48a6fd0e1398ed1e26f928726fec', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitcaaf9e35911715a011b2dd61314f87c4::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit69ca48a6fd0e1398ed1e26f928726fec::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInitcaaf9e35911715a011b2dd61314f87c4::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit69ca48a6fd0e1398ed1e26f928726fec::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequirecaaf9e35911715a011b2dd61314f87c4($fileIdentifier, $file);
|
||||
composerRequire69ca48a6fd0e1398ed1e26f928726fec($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
|
@ -46,7 +46,7 @@ class ComposerAutoloaderInitcaaf9e35911715a011b2dd61314f87c4
|
|||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequirecaaf9e35911715a011b2dd61314f87c4($fileIdentifier, $file)
|
||||
function composerRequire69ca48a6fd0e1398ed1e26f928726fec($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 ComposerStaticInitcaaf9e35911715a011b2dd61314f87c4
|
||||
class ComposerStaticInit69ca48a6fd0e1398ed1e26f928726fec
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -1402,6 +1402,7 @@ class ComposerStaticInitcaaf9e35911715a011b2dd61314f87c4
|
|||
'Rector\\CodeQuality\\Rector\\BooleanNot\\ReplaceMultipleBooleanNotRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/BooleanNot/ReplaceMultipleBooleanNotRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\BooleanNot\\SimplifyDeMorganBinaryRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/BooleanNot/SimplifyDeMorganBinaryRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\Catch_\\ThrowWithPreviousExceptionRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/Catch_/ThrowWithPreviousExceptionRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\ClassConstFetch\\ConvertStaticPrivateConstantToSelfRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/ClassConstFetch/ConvertStaticPrivateConstantToSelfRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\ClassMethod\\InlineArrayReturnAssignRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/ClassMethod/InlineArrayReturnAssignRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\ClassMethod\\NarrowUnionTypeDocRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/ClassMethod/NarrowUnionTypeDocRector.php',
|
||||
'Rector\\CodeQuality\\Rector\\ClassMethod\\OptionalParametersAfterRequiredRector' => __DIR__ . '/../..' . '/rules/CodeQuality/Rector/ClassMethod/OptionalParametersAfterRequiredRector.php',
|
||||
|
@ -3026,9 +3027,9 @@ class ComposerStaticInitcaaf9e35911715a011b2dd61314f87c4
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitcaaf9e35911715a011b2dd61314f87c4::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitcaaf9e35911715a011b2dd61314f87c4::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitcaaf9e35911715a011b2dd61314f87c4::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit69ca48a6fd0e1398ed1e26f928726fec::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit69ca48a6fd0e1398ed1e26f928726fec::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit69ca48a6fd0e1398ed1e26f928726fec::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user