Updated Rector to commit 581fba01dfcc247be5dcec00903b72739b7eca6d

581fba01df [Php55] Add StaticToSelfOnFinalClassRector (#3629)
This commit is contained in:
Tomas Votruba 2023-04-19 07:12:58 +00:00
parent f00ddc261c
commit 4980a45b0b
11 changed files with 150 additions and 24 deletions

View File

@ -5,6 +5,7 @@ namespace RectorPrefix202304;
use Rector\Config\RectorConfig; use Rector\Config\RectorConfig;
use Rector\Php55\Rector\Class_\ClassConstantToSelfClassRector; use Rector\Php55\Rector\Class_\ClassConstantToSelfClassRector;
use Rector\Php55\Rector\ClassConstFetch\StaticToSelfOnFinalClassRector;
use Rector\Php55\Rector\FuncCall\GetCalledClassToSelfClassRector; use Rector\Php55\Rector\FuncCall\GetCalledClassToSelfClassRector;
use Rector\Php55\Rector\FuncCall\GetCalledClassToStaticClassRector; use Rector\Php55\Rector\FuncCall\GetCalledClassToStaticClassRector;
use Rector\Php55\Rector\FuncCall\PregReplaceEModifierRector; use Rector\Php55\Rector\FuncCall\PregReplaceEModifierRector;
@ -15,4 +16,5 @@ return static function (RectorConfig $rectorConfig) : void {
$rectorConfig->rule(PregReplaceEModifierRector::class); $rectorConfig->rule(PregReplaceEModifierRector::class);
$rectorConfig->rule(GetCalledClassToSelfClassRector::class); $rectorConfig->rule(GetCalledClassToSelfClassRector::class);
$rectorConfig->rule(GetCalledClassToStaticClassRector::class); $rectorConfig->rule(GetCalledClassToStaticClassRector::class);
$rectorConfig->rule(StaticToSelfOnFinalClassRector::class);
}; };

View File

@ -1,4 +1,4 @@
# 416 Rules Overview # 418 Rules Overview
<br> <br>
@ -30,7 +30,7 @@
- [Php54](#php54) (3) - [Php54](#php54) (3)
- [Php55](#php55) (5) - [Php55](#php55) (6)
- [Php56](#php56) (2) - [Php56](#php56) (2)
@ -64,7 +64,7 @@
- [Transform](#transform) (34) - [Transform](#transform) (34)
- [TypeDeclaration](#typedeclaration) (37) - [TypeDeclaration](#typedeclaration) (38)
- [Visibility](#visibility) (3) - [Visibility](#visibility) (3)
@ -4703,6 +4703,25 @@ The /e modifier is no longer supported, use preg_replace_callback instead
<br> <br>
### StaticToSelfOnFinalClassRector
Change `static::class` to `self::class` on final class
- class: [`Rector\Php55\Rector\ClassConstFetch\StaticToSelfOnFinalClassRector`](../rules/Php55/Rector/ClassConstFetch/StaticToSelfOnFinalClassRector.php)
```diff
final class SomeClass
{
public function callOnMe()
{
- var_dump(static::class);
+ var_dump(self::class);
}
}
```
<br>
### StringClassNameToClassConstantRector ### StringClassNameToClassConstantRector
Replace string class names by <class>::class constant Replace string class names by <class>::class constant
@ -9514,6 +9533,22 @@ Add array shape exact types based on constant keys of array
<br> <br>
### DeclareStrictTypesRector
Add declare(strict_types=1) if missing
- class: [`Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector`](../rules/TypeDeclaration/Rector/StmtsAwareInterface/DeclareStrictTypesRector.php)
```diff
+declare(strict_types=1);
+
function someFunction()
{
}
```
<br>
### EmptyOnNullableObjectToInstanceOfRector ### EmptyOnNullableObjectToInstanceOfRector
Change `empty()` on nullable object to instanceof check Change `empty()` on nullable object to instanceof check

View File

@ -0,0 +1,83 @@
<?php
declare (strict_types=1);
namespace Rector\Php55\Rector\ClassConstFetch;
use PhpParser\Node;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\Class_;
use Rector\Core\Enum\ObjectReference;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://wiki.php.net/rfc/class_name_scalars
* @changelog https://3v4l.org/AHr9C#v5.5.0
* @see \Rector\Tests\Php55\Rector\ClassConstFetch\StaticToSelfOnFinalClassRector\StaticToSelfOnFinalClassRectorTest
*/
final class StaticToSelfOnFinalClassRector extends AbstractRector implements MinPhpVersionInterface
{
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Change `static::class` to `self::class` on final class', [new CodeSample(<<<'CODE_SAMPLE'
final class SomeClass
{
public function callOnMe()
{
var_dump(static::class);
}
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
final class SomeClass
{
public function callOnMe()
{
var_dump(self::class);
}
}
CODE_SAMPLE
)]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [ClassConstFetch::class];
}
/**
* @param ClassConstFetch $node
*/
public function refactor(Node $node) : ?ClassConstFetch
{
if (!$node->class instanceof Name) {
return null;
}
if (!$node->name instanceof Identifier) {
return null;
}
if ($node->class->toString() !== ObjectReference::STATIC) {
return null;
}
if ($node->name->toString() !== 'class') {
return null;
}
$class = $this->betterNodeFinder->findParentType($node, Class_::class);
if (!$class instanceof Class_) {
return null;
}
if (!$class->isFinal()) {
return null;
}
return $this->nodeFactory->createSelfFetchConstant('class');
}
public function provideMinPhpVersion() : int
{
return PhpVersionFeature::CLASSNAME_CONSTANT;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api * @api
* @var string * @var string
*/ */
public const PACKAGE_VERSION = '14cc7d49406c55acd1ce7e83c7cddd23b9fd12a2'; public const PACKAGE_VERSION = '581fba01dfcc247be5dcec00903b72739b7eca6d';
/** /**
* @api * @api
* @var string * @var string
*/ */
public const RELEASE_DATE = '2023-04-18 12:07:14'; public const RELEASE_DATE = '2023-04-19 09:08:15';
/** /**
* @var int * @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'; require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit8281a6b78bcb82bc71d9ac10027263e9::getLoader(); return ComposerAutoloaderInit0fbb584a8ef45fbb4ccffbd83f0d6f7c::getLoader();

View File

@ -2182,6 +2182,7 @@ return array(
'Rector\\Php54\\Rector\\Array_\\LongArrayToShortArrayRector' => $baseDir . '/rules/Php54/Rector/Array_/LongArrayToShortArrayRector.php', 'Rector\\Php54\\Rector\\Array_\\LongArrayToShortArrayRector' => $baseDir . '/rules/Php54/Rector/Array_/LongArrayToShortArrayRector.php',
'Rector\\Php54\\Rector\\Break_\\RemoveZeroBreakContinueRector' => $baseDir . '/rules/Php54/Rector/Break_/RemoveZeroBreakContinueRector.php', 'Rector\\Php54\\Rector\\Break_\\RemoveZeroBreakContinueRector' => $baseDir . '/rules/Php54/Rector/Break_/RemoveZeroBreakContinueRector.php',
'Rector\\Php54\\Rector\\FuncCall\\RemoveReferenceFromCallRector' => $baseDir . '/rules/Php54/Rector/FuncCall/RemoveReferenceFromCallRector.php', 'Rector\\Php54\\Rector\\FuncCall\\RemoveReferenceFromCallRector' => $baseDir . '/rules/Php54/Rector/FuncCall/RemoveReferenceFromCallRector.php',
'Rector\\Php55\\Rector\\ClassConstFetch\\StaticToSelfOnFinalClassRector' => $baseDir . '/rules/Php55/Rector/ClassConstFetch/StaticToSelfOnFinalClassRector.php',
'Rector\\Php55\\Rector\\Class_\\ClassConstantToSelfClassRector' => $baseDir . '/rules/Php55/Rector/Class_/ClassConstantToSelfClassRector.php', 'Rector\\Php55\\Rector\\Class_\\ClassConstantToSelfClassRector' => $baseDir . '/rules/Php55/Rector/Class_/ClassConstantToSelfClassRector.php',
'Rector\\Php55\\Rector\\FuncCall\\GetCalledClassToSelfClassRector' => $baseDir . '/rules/Php55/Rector/FuncCall/GetCalledClassToSelfClassRector.php', 'Rector\\Php55\\Rector\\FuncCall\\GetCalledClassToSelfClassRector' => $baseDir . '/rules/Php55/Rector/FuncCall/GetCalledClassToSelfClassRector.php',
'Rector\\Php55\\Rector\\FuncCall\\GetCalledClassToStaticClassRector' => $baseDir . '/rules/Php55/Rector/FuncCall/GetCalledClassToStaticClassRector.php', 'Rector\\Php55\\Rector\\FuncCall\\GetCalledClassToStaticClassRector' => $baseDir . '/rules/Php55/Rector/FuncCall/GetCalledClassToStaticClassRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInit8281a6b78bcb82bc71d9ac10027263e9 class ComposerAutoloaderInit0fbb584a8ef45fbb4ccffbd83f0d6f7c
{ {
private static $loader; private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit8281a6b78bcb82bc71d9ac10027263e9
return self::$loader; return self::$loader;
} }
spl_autoload_register(array('ComposerAutoloaderInit8281a6b78bcb82bc71d9ac10027263e9', 'loadClassLoader'), true, true); spl_autoload_register(array('ComposerAutoloaderInit0fbb584a8ef45fbb4ccffbd83f0d6f7c', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit8281a6b78bcb82bc71d9ac10027263e9', 'loadClassLoader')); spl_autoload_unregister(array('ComposerAutoloaderInit0fbb584a8ef45fbb4ccffbd83f0d6f7c', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php'; require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit8281a6b78bcb82bc71d9ac10027263e9::getInitializer($loader)); call_user_func(\Composer\Autoload\ComposerStaticInit0fbb584a8ef45fbb4ccffbd83f0d6f7c::getInitializer($loader));
$loader->setClassMapAuthoritative(true); $loader->setClassMapAuthoritative(true);
$loader->register(true); $loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit8281a6b78bcb82bc71d9ac10027263e9::$files; $filesToLoad = \Composer\Autoload\ComposerStaticInit0fbb584a8ef45fbb4ccffbd83f0d6f7c::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) { $requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload; namespace Composer\Autoload;
class ComposerStaticInit8281a6b78bcb82bc71d9ac10027263e9 class ComposerStaticInit0fbb584a8ef45fbb4ccffbd83f0d6f7c
{ {
public static $files = array ( public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2429,6 +2429,7 @@ class ComposerStaticInit8281a6b78bcb82bc71d9ac10027263e9
'Rector\\Php54\\Rector\\Array_\\LongArrayToShortArrayRector' => __DIR__ . '/../..' . '/rules/Php54/Rector/Array_/LongArrayToShortArrayRector.php', 'Rector\\Php54\\Rector\\Array_\\LongArrayToShortArrayRector' => __DIR__ . '/../..' . '/rules/Php54/Rector/Array_/LongArrayToShortArrayRector.php',
'Rector\\Php54\\Rector\\Break_\\RemoveZeroBreakContinueRector' => __DIR__ . '/../..' . '/rules/Php54/Rector/Break_/RemoveZeroBreakContinueRector.php', 'Rector\\Php54\\Rector\\Break_\\RemoveZeroBreakContinueRector' => __DIR__ . '/../..' . '/rules/Php54/Rector/Break_/RemoveZeroBreakContinueRector.php',
'Rector\\Php54\\Rector\\FuncCall\\RemoveReferenceFromCallRector' => __DIR__ . '/../..' . '/rules/Php54/Rector/FuncCall/RemoveReferenceFromCallRector.php', 'Rector\\Php54\\Rector\\FuncCall\\RemoveReferenceFromCallRector' => __DIR__ . '/../..' . '/rules/Php54/Rector/FuncCall/RemoveReferenceFromCallRector.php',
'Rector\\Php55\\Rector\\ClassConstFetch\\StaticToSelfOnFinalClassRector' => __DIR__ . '/../..' . '/rules/Php55/Rector/ClassConstFetch/StaticToSelfOnFinalClassRector.php',
'Rector\\Php55\\Rector\\Class_\\ClassConstantToSelfClassRector' => __DIR__ . '/../..' . '/rules/Php55/Rector/Class_/ClassConstantToSelfClassRector.php', 'Rector\\Php55\\Rector\\Class_\\ClassConstantToSelfClassRector' => __DIR__ . '/../..' . '/rules/Php55/Rector/Class_/ClassConstantToSelfClassRector.php',
'Rector\\Php55\\Rector\\FuncCall\\GetCalledClassToSelfClassRector' => __DIR__ . '/../..' . '/rules/Php55/Rector/FuncCall/GetCalledClassToSelfClassRector.php', 'Rector\\Php55\\Rector\\FuncCall\\GetCalledClassToSelfClassRector' => __DIR__ . '/../..' . '/rules/Php55/Rector/FuncCall/GetCalledClassToSelfClassRector.php',
'Rector\\Php55\\Rector\\FuncCall\\GetCalledClassToStaticClassRector' => __DIR__ . '/../..' . '/rules/Php55/Rector/FuncCall/GetCalledClassToStaticClassRector.php', 'Rector\\Php55\\Rector\\FuncCall\\GetCalledClassToStaticClassRector' => __DIR__ . '/../..' . '/rules/Php55/Rector/FuncCall/GetCalledClassToStaticClassRector.php',
@ -3142,9 +3143,9 @@ class ComposerStaticInit8281a6b78bcb82bc71d9ac10027263e9
public static function getInitializer(ClassLoader $loader) public static function getInitializer(ClassLoader $loader)
{ {
return \Closure::bind(function () use ($loader) { return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit8281a6b78bcb82bc71d9ac10027263e9::$prefixLengthsPsr4; $loader->prefixLengthsPsr4 = ComposerStaticInit0fbb584a8ef45fbb4ccffbd83f0d6f7c::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit8281a6b78bcb82bc71d9ac10027263e9::$prefixDirsPsr4; $loader->prefixDirsPsr4 = ComposerStaticInit0fbb584a8ef45fbb4ccffbd83f0d6f7c::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit8281a6b78bcb82bc71d9ac10027263e9::$classMap; $loader->classMap = ComposerStaticInit0fbb584a8ef45fbb4ccffbd83f0d6f7c::$classMap;
}, null, ClassLoader::class); }, null, ClassLoader::class);
} }

View File

@ -821,17 +821,17 @@
}, },
{ {
"name": "phpstan\/phpdoc-parser", "name": "phpstan\/phpdoc-parser",
"version": "1.19.0", "version": "1.19.1",
"version_normalized": "1.19.0.0", "version_normalized": "1.19.1.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https:\/\/github.com\/phpstan\/phpdoc-parser.git", "url": "https:\/\/github.com\/phpstan\/phpdoc-parser.git",
"reference": "178b33aa1c8b8d7725f0abee618ef47337e607ce" "reference": "f545fc30978190a056832aa7ed995e36a66267f3"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpdoc-parser\/zipball\/178b33aa1c8b8d7725f0abee618ef47337e607ce", "url": "https:\/\/api.github.com\/repos\/phpstan\/phpdoc-parser\/zipball\/f545fc30978190a056832aa7ed995e36a66267f3",
"reference": "178b33aa1c8b8d7725f0abee618ef47337e607ce", "reference": "f545fc30978190a056832aa7ed995e36a66267f3",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -846,7 +846,7 @@
"phpunit\/phpunit": "^9.5", "phpunit\/phpunit": "^9.5",
"symfony\/process": "^5.2" "symfony\/process": "^5.2"
}, },
"time": "2023-04-17T13:16:52+00:00", "time": "2023-04-18T11:30:56+00:00",
"type": "library", "type": "library",
"installation-source": "dist", "installation-source": "dist",
"autoload": { "autoload": {
@ -863,7 +863,7 @@
"description": "PHPDoc parser with support for nullable, intersection and generic types", "description": "PHPDoc parser with support for nullable, intersection and generic types",
"support": { "support": {
"issues": "https:\/\/github.com\/phpstan\/phpdoc-parser\/issues", "issues": "https:\/\/github.com\/phpstan\/phpdoc-parser\/issues",
"source": "https:\/\/github.com\/phpstan\/phpdoc-parser\/tree\/1.19.0" "source": "https:\/\/github.com\/phpstan\/phpdoc-parser\/tree\/1.19.1"
}, },
"install-path": "..\/phpstan\/phpdoc-parser" "install-path": "..\/phpstan\/phpdoc-parser"
}, },

File diff suppressed because one or more lines are too long

View File

@ -22,7 +22,11 @@ class CallableTypeNode implements \PHPStan\PhpDocParser\Ast\Type\TypeNode
} }
public function __toString() : string public function __toString() : string
{ {
$returnType = $this->returnType;
if ($returnType instanceof self) {
$returnType = "({$returnType})";
}
$parameters = implode(', ', $this->parameters); $parameters = implode(', ', $this->parameters);
return "{$this->identifier}({$parameters}): {$this->returnType}"; return "{$this->identifier}({$parameters}): {$returnType}";
} }
} }