diff --git a/config/set/php74.php b/config/set/php74.php
index 014e5b87eb7..7bf68194ff4 100644
--- a/config/set/php74.php
+++ b/config/set/php74.php
@@ -10,6 +10,7 @@ use Rector\Php74\Rector\Double\RealToFloatTypeCastRector;
use Rector\Php74\Rector\FuncCall\ArrayKeyExistsOnPropertyRector;
use Rector\Php74\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector;
use Rector\Php74\Rector\FuncCall\FilterVarToAddSlashesRector;
+use Rector\Php74\Rector\FuncCall\GetCalledClassToSelfClassRector;
use Rector\Php74\Rector\FuncCall\GetCalledClassToStaticClassRector;
use Rector\Php74\Rector\FuncCall\MbStrrposEncodingArgumentPositionRector;
use Rector\Php74\Rector\Function_\ReservedFnFunctionRector;
@@ -34,6 +35,7 @@ return static function (\Symfony\Component\DependencyInjection\Loader\Configurat
$services->set(\Rector\Php74\Rector\FuncCall\ArrayKeyExistsOnPropertyRector::class);
$services->set(\Rector\Php74\Rector\FuncCall\FilterVarToAddSlashesRector::class);
$services->set(\Rector\Php74\Rector\StaticCall\ExportToReflectionFunctionRector::class);
+ $services->set(\Rector\Php74\Rector\FuncCall\GetCalledClassToSelfClassRector::class);
$services->set(\Rector\Php74\Rector\FuncCall\GetCalledClassToStaticClassRector::class);
$services->set(\Rector\Php74\Rector\FuncCall\MbStrrposEncodingArgumentPositionRector::class);
$services->set(\Rector\Php74\Rector\Double\RealToFloatTypeCastRector::class);
diff --git a/docs/rector_rules_overview.md b/docs/rector_rules_overview.md
index ec7928d1c7d..9491c1f4d9f 100644
--- a/docs/rector_rules_overview.md
+++ b/docs/rector_rules_overview.md
@@ -1,4 +1,4 @@
-# 506 Rules Overview
+# 507 Rules Overview
@@ -66,7 +66,7 @@
- [Php73](#php73) (9)
-- [Php74](#php74) (15)
+- [Php74](#php74) (16)
- [Php80](#php80) (17)
@@ -7837,9 +7837,28 @@ Change `filter_var()` with slash escaping to `addslashes()`
+### GetCalledClassToSelfClassRector
+
+Change `get_called_class()` to self::class on final class
+
+- class: [`Rector\Php74\Rector\FuncCall\GetCalledClassToSelfClassRector`](../rules/Php74/Rector/FuncCall/GetCalledClassToSelfClassRector.php)
+
+```diff
+ final class SomeClass
+ {
+ public function callOnMe()
+ {
+- var_dump(get_called_class());
++ var_dump(self::class);
+ }
+ }
+```
+
+
+
### GetCalledClassToStaticClassRector
-Change `get_called_class()` to static::class
+Change `get_called_class()` to static::class on non-final class
- class: [`Rector\Php74\Rector\FuncCall\GetCalledClassToStaticClassRector`](../rules/Php74/Rector/FuncCall/GetCalledClassToStaticClassRector.php)
diff --git a/rules/Php74/Rector/FuncCall/GetCalledClassToSelfClassRector.php b/rules/Php74/Rector/FuncCall/GetCalledClassToSelfClassRector.php
new file mode 100644
index 00000000000..f251409390b
--- /dev/null
+++ b/rules/Php74/Rector/FuncCall/GetCalledClassToSelfClassRector.php
@@ -0,0 +1,85 @@
+classAnalyzer = $classAnalyzer;
+ }
+ public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
+ {
+ return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Change get_called_class() to self::class on final class', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
+final class SomeClass
+{
+ public function callOnMe()
+ {
+ var_dump(get_called_class());
+ }
+}
+CODE_SAMPLE
+, <<<'CODE_SAMPLE'
+final class SomeClass
+{
+ public function callOnMe()
+ {
+ var_dump(self::class);
+ }
+}
+CODE_SAMPLE
+)]);
+ }
+ /**
+ * @return array>
+ */
+ public function getNodeTypes() : array
+ {
+ return [\PhpParser\Node\Expr\FuncCall::class];
+ }
+ /**
+ * @param FuncCall $node
+ */
+ public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
+ {
+ if (!$this->isName($node, 'get_called_class')) {
+ return null;
+ }
+ $class = $this->betterNodeFinder->findParentType($node, \PhpParser\Node\Stmt\Class_::class);
+ if (!$class instanceof \PhpParser\Node\Stmt\Class_) {
+ return null;
+ }
+ if ($class->isFinal()) {
+ return $this->nodeFactory->createClassConstFetch(\Rector\Core\Enum\ObjectReference::SELF(), 'class');
+ }
+ if ($this->classAnalyzer->isAnonymousClass($class)) {
+ return $this->nodeFactory->createClassConstFetch(\Rector\Core\Enum\ObjectReference::SELF(), 'class');
+ }
+ return null;
+ }
+ public function provideMinPhpVersion() : int
+ {
+ return \Rector\Core\ValueObject\PhpVersionFeature::CLASSNAME_CONSTANT;
+ }
+}
diff --git a/rules/Php74/Rector/FuncCall/GetCalledClassToStaticClassRector.php b/rules/Php74/Rector/FuncCall/GetCalledClassToStaticClassRector.php
index bd451531ff2..dc30210da8a 100644
--- a/rules/Php74/Rector/FuncCall/GetCalledClassToStaticClassRector.php
+++ b/rules/Php74/Rector/FuncCall/GetCalledClassToStaticClassRector.php
@@ -5,7 +5,9 @@ namespace Rector\Php74\Rector\FuncCall;
use PhpParser\Node;
use PhpParser\Node\Expr\FuncCall;
+use PhpParser\Node\Stmt\Class_;
use Rector\Core\Enum\ObjectReference;
+use Rector\Core\NodeAnalyzer\ClassAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
@@ -18,9 +20,18 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class GetCalledClassToStaticClassRector extends \Rector\Core\Rector\AbstractRector implements \Rector\VersionBonding\Contract\MinPhpVersionInterface
{
+ /**
+ * @readonly
+ * @var \Rector\Core\NodeAnalyzer\ClassAnalyzer
+ */
+ private $classAnalyzer;
+ public function __construct(\Rector\Core\NodeAnalyzer\ClassAnalyzer $classAnalyzer)
+ {
+ $this->classAnalyzer = $classAnalyzer;
+ }
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
- return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Change get_called_class() to static::class', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
+ return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Change get_called_class() to static::class on non-final class', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
class SomeClass
{
public function callOnMe()
@@ -55,7 +66,17 @@ CODE_SAMPLE
if (!$this->isName($node, 'get_called_class')) {
return null;
}
- return $this->nodeFactory->createClassConstFetch(\Rector\Core\Enum\ObjectReference::STATIC(), 'class');
+ $class = $this->betterNodeFinder->findParentType($node, \PhpParser\Node\Stmt\Class_::class);
+ if (!$class instanceof \PhpParser\Node\Stmt\Class_) {
+ return $this->nodeFactory->createClassConstFetch(\Rector\Core\Enum\ObjectReference::STATIC(), 'class');
+ }
+ if ($this->classAnalyzer->isAnonymousClass($class)) {
+ return null;
+ }
+ if (!$class->isFinal()) {
+ return $this->nodeFactory->createClassConstFetch(\Rector\Core\Enum\ObjectReference::STATIC(), 'class');
+ }
+ return null;
}
public function provideMinPhpVersion() : int
{
diff --git a/rules/Php81/Rector/ClassConst/FinalizePublicClassConstantRector.php b/rules/Php81/Rector/ClassConst/FinalizePublicClassConstantRector.php
index 32e6202e038..be8aab3ae78 100644
--- a/rules/Php81/Rector/ClassConst/FinalizePublicClassConstantRector.php
+++ b/rules/Php81/Rector/ClassConst/FinalizePublicClassConstantRector.php
@@ -84,15 +84,15 @@ CODE_SAMPLE
if ($class->isFinal()) {
return null;
}
- if ($node->isPrivate()) {
- return null;
- }
- if ($node->isProtected()) {
+ if (!$node->isPublic()) {
return null;
}
if ($node->isFinal()) {
return null;
}
+ if ($this->classAnalyzer->isAnonymousClass($class)) {
+ return null;
+ }
if ($this->isClassHasChildren($class)) {
return null;
}
@@ -105,9 +105,6 @@ CODE_SAMPLE
}
private function isClassHasChildren(\PhpParser\Node\Stmt\Class_ $class) : bool
{
- if ($this->classAnalyzer->isAnonymousClass($class)) {
- return \false;
- }
$className = (string) $this->nodeNameResolver->getName($class);
if (!$this->reflectionProvider->hasClass($className)) {
return \false;
diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php
index 46672bc2806..e4c8e936600 100644
--- a/src/Application/VersionResolver.php
+++ b/src/Application/VersionResolver.php
@@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
- public const PACKAGE_VERSION = '82656ade38409a188114aebd347ff9a2b5af97ba';
+ public const PACKAGE_VERSION = '90bbd4e1a03b4404b3988c863fb3e46d0fa1411b';
/**
* @var string
*/
- public const RELEASE_DATE = '2022-03-27 20:36:49';
+ public const RELEASE_DATE = '2022-03-27 20:38:09';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20220327\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
diff --git a/vendor/autoload.php b/vendor/autoload.php
index c2575e5a77f..637afc06a2f 100644
--- a/vendor/autoload.php
+++ b/vendor/autoload.php
@@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
-return ComposerAutoloaderInit8dff0a86436b1a661f6807b929cb0524::getLoader();
+return ComposerAutoloaderInit92f7be94f77045afc7362469e574fa89::getLoader();
diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php
index f776a57fd25..a38c72ce65d 100644
--- a/vendor/composer/autoload_classmap.php
+++ b/vendor/composer/autoload_classmap.php
@@ -2625,6 +2625,7 @@ return array(
'Rector\\Php74\\Rector\\FuncCall\\ArrayKeyExistsOnPropertyRector' => $baseDir . '/rules/Php74/Rector/FuncCall/ArrayKeyExistsOnPropertyRector.php',
'Rector\\Php74\\Rector\\FuncCall\\ArraySpreadInsteadOfArrayMergeRector' => $baseDir . '/rules/Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php',
'Rector\\Php74\\Rector\\FuncCall\\FilterVarToAddSlashesRector' => $baseDir . '/rules/Php74/Rector/FuncCall/FilterVarToAddSlashesRector.php',
+ 'Rector\\Php74\\Rector\\FuncCall\\GetCalledClassToSelfClassRector' => $baseDir . '/rules/Php74/Rector/FuncCall/GetCalledClassToSelfClassRector.php',
'Rector\\Php74\\Rector\\FuncCall\\GetCalledClassToStaticClassRector' => $baseDir . '/rules/Php74/Rector/FuncCall/GetCalledClassToStaticClassRector.php',
'Rector\\Php74\\Rector\\FuncCall\\MbStrrposEncodingArgumentPositionRector' => $baseDir . '/rules/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector.php',
'Rector\\Php74\\Rector\\Function_\\ReservedFnFunctionRector' => $baseDir . '/rules/Php74/Rector/Function_/ReservedFnFunctionRector.php',
diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php
index 60c0cef3292..225c86a3598 100644
--- a/vendor/composer/autoload_real.php
+++ b/vendor/composer/autoload_real.php
@@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
-class ComposerAutoloaderInit8dff0a86436b1a661f6807b929cb0524
+class ComposerAutoloaderInit92f7be94f77045afc7362469e574fa89
{
private static $loader;
@@ -22,15 +22,15 @@ class ComposerAutoloaderInit8dff0a86436b1a661f6807b929cb0524
return self::$loader;
}
- spl_autoload_register(array('ComposerAutoloaderInit8dff0a86436b1a661f6807b929cb0524', 'loadClassLoader'), true, true);
+ spl_autoload_register(array('ComposerAutoloaderInit92f7be94f77045afc7362469e574fa89', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
- spl_autoload_unregister(array('ComposerAutoloaderInit8dff0a86436b1a661f6807b929cb0524', 'loadClassLoader'));
+ spl_autoload_unregister(array('ComposerAutoloaderInit92f7be94f77045afc7362469e574fa89', '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\ComposerStaticInit8dff0a86436b1a661f6807b929cb0524::getInitializer($loader));
+ call_user_func(\Composer\Autoload\ComposerStaticInit92f7be94f77045afc7362469e574fa89::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@@ -42,12 +42,12 @@ class ComposerAutoloaderInit8dff0a86436b1a661f6807b929cb0524
$loader->register(true);
if ($useStaticLoader) {
- $includeFiles = Composer\Autoload\ComposerStaticInit8dff0a86436b1a661f6807b929cb0524::$files;
+ $includeFiles = Composer\Autoload\ComposerStaticInit92f7be94f77045afc7362469e574fa89::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
- composerRequire8dff0a86436b1a661f6807b929cb0524($fileIdentifier, $file);
+ composerRequire92f7be94f77045afc7362469e574fa89($fileIdentifier, $file);
}
return $loader;
@@ -59,7 +59,7 @@ class ComposerAutoloaderInit8dff0a86436b1a661f6807b929cb0524
* @param string $file
* @return void
*/
-function composerRequire8dff0a86436b1a661f6807b929cb0524($fileIdentifier, $file)
+function composerRequire92f7be94f77045afc7362469e574fa89($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php
index 8c37b05af82..54f0da02d6a 100644
--- a/vendor/composer/autoload_static.php
+++ b/vendor/composer/autoload_static.php
@@ -4,7 +4,7 @@
namespace Composer\Autoload;
-class ComposerStaticInit8dff0a86436b1a661f6807b929cb0524
+class ComposerStaticInit92f7be94f77045afc7362469e574fa89
{
public static $files = array (
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
@@ -2994,6 +2994,7 @@ class ComposerStaticInit8dff0a86436b1a661f6807b929cb0524
'Rector\\Php74\\Rector\\FuncCall\\ArrayKeyExistsOnPropertyRector' => __DIR__ . '/../..' . '/rules/Php74/Rector/FuncCall/ArrayKeyExistsOnPropertyRector.php',
'Rector\\Php74\\Rector\\FuncCall\\ArraySpreadInsteadOfArrayMergeRector' => __DIR__ . '/../..' . '/rules/Php74/Rector/FuncCall/ArraySpreadInsteadOfArrayMergeRector.php',
'Rector\\Php74\\Rector\\FuncCall\\FilterVarToAddSlashesRector' => __DIR__ . '/../..' . '/rules/Php74/Rector/FuncCall/FilterVarToAddSlashesRector.php',
+ 'Rector\\Php74\\Rector\\FuncCall\\GetCalledClassToSelfClassRector' => __DIR__ . '/../..' . '/rules/Php74/Rector/FuncCall/GetCalledClassToSelfClassRector.php',
'Rector\\Php74\\Rector\\FuncCall\\GetCalledClassToStaticClassRector' => __DIR__ . '/../..' . '/rules/Php74/Rector/FuncCall/GetCalledClassToStaticClassRector.php',
'Rector\\Php74\\Rector\\FuncCall\\MbStrrposEncodingArgumentPositionRector' => __DIR__ . '/../..' . '/rules/Php74/Rector/FuncCall/MbStrrposEncodingArgumentPositionRector.php',
'Rector\\Php74\\Rector\\Function_\\ReservedFnFunctionRector' => __DIR__ . '/../..' . '/rules/Php74/Rector/Function_/ReservedFnFunctionRector.php',
@@ -3837,9 +3838,9 @@ class ComposerStaticInit8dff0a86436b1a661f6807b929cb0524
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
- $loader->prefixLengthsPsr4 = ComposerStaticInit8dff0a86436b1a661f6807b929cb0524::$prefixLengthsPsr4;
- $loader->prefixDirsPsr4 = ComposerStaticInit8dff0a86436b1a661f6807b929cb0524::$prefixDirsPsr4;
- $loader->classMap = ComposerStaticInit8dff0a86436b1a661f6807b929cb0524::$classMap;
+ $loader->prefixLengthsPsr4 = ComposerStaticInit92f7be94f77045afc7362469e574fa89::$prefixLengthsPsr4;
+ $loader->prefixDirsPsr4 = ComposerStaticInit92f7be94f77045afc7362469e574fa89::$prefixDirsPsr4;
+ $loader->classMap = ComposerStaticInit92f7be94f77045afc7362469e574fa89::$classMap;
}, null, ClassLoader::class);
}
diff --git a/vendor/scoper-autoload.php b/vendor/scoper-autoload.php
index 3de38ba08b7..2f425b78648 100644
--- a/vendor/scoper-autoload.php
+++ b/vendor/scoper-autoload.php
@@ -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('RectorPrefix20220327\AutoloadIncluder');
}
-if (!class_exists('ComposerAutoloaderInit8dff0a86436b1a661f6807b929cb0524', false) && !interface_exists('ComposerAutoloaderInit8dff0a86436b1a661f6807b929cb0524', false) && !trait_exists('ComposerAutoloaderInit8dff0a86436b1a661f6807b929cb0524', false)) {
- spl_autoload_call('RectorPrefix20220327\ComposerAutoloaderInit8dff0a86436b1a661f6807b929cb0524');
+if (!class_exists('ComposerAutoloaderInit92f7be94f77045afc7362469e574fa89', false) && !interface_exists('ComposerAutoloaderInit92f7be94f77045afc7362469e574fa89', false) && !trait_exists('ComposerAutoloaderInit92f7be94f77045afc7362469e574fa89', false)) {
+ spl_autoload_call('RectorPrefix20220327\ComposerAutoloaderInit92f7be94f77045afc7362469e574fa89');
}
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
spl_autoload_call('RectorPrefix20220327\Helmich\TypoScriptParser\Parser\AST\Statement');
@@ -59,9 +59,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220327\print_node(...func_get_args());
}
}
-if (!function_exists('composerRequire8dff0a86436b1a661f6807b929cb0524')) {
- function composerRequire8dff0a86436b1a661f6807b929cb0524() {
- return \RectorPrefix20220327\composerRequire8dff0a86436b1a661f6807b929cb0524(...func_get_args());
+if (!function_exists('composerRequire92f7be94f77045afc7362469e574fa89')) {
+ function composerRequire92f7be94f77045afc7362469e574fa89() {
+ return \RectorPrefix20220327\composerRequire92f7be94f77045afc7362469e574fa89(...func_get_args());
}
}
if (!function_exists('scanPath')) {