mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-27 13:13:31 +00:00
Updated Rector to commit 967279219d
967279219d
[PHP 8.2] Skip readonly class on property without type in ReadOnlyClassRector (#2398)
This commit is contained in:
parent
8779477bf1
commit
82e4121076
|
@ -4,6 +4,7 @@ declare (strict_types=1);
|
|||
namespace Rector\Php82\Rector\Class_;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
|
@ -104,23 +105,19 @@ CODE_SAMPLE
|
|||
}
|
||||
private function shouldSkip(\PhpParser\Node\Stmt\Class_ $class) : bool
|
||||
{
|
||||
// need to have test fixture once feature added to nikic/PHP-Parser
|
||||
if ($this->visibilityManipulator->hasVisibility($class, \Rector\Core\ValueObject\Visibility::READONLY)) {
|
||||
return \true;
|
||||
}
|
||||
if ($this->classAnalyzer->isAnonymousClass($class)) {
|
||||
return \true;
|
||||
}
|
||||
if (!$class->isFinal()) {
|
||||
return \true;
|
||||
}
|
||||
if ($this->phpAttributeAnalyzer->hasPhpAttribute($class, self::ATTRIBUTE)) {
|
||||
if ($this->shouldSkipClass($class)) {
|
||||
return \true;
|
||||
}
|
||||
$properties = $class->getProperties();
|
||||
if ($this->hasWritableProperty($properties)) {
|
||||
return \true;
|
||||
}
|
||||
foreach ($properties as $property) {
|
||||
// properties of readonly class must always have type
|
||||
if ($property->type === null) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
$constructClassMethod = $class->getMethod(\Rector\Core\ValueObject\MethodName::CONSTRUCT);
|
||||
if (!$constructClassMethod instanceof \PhpParser\Node\Stmt\ClassMethod) {
|
||||
// no __construct means no property promotion, skip if class has no property defined
|
||||
|
@ -131,13 +128,7 @@ CODE_SAMPLE
|
|||
// no params means no property promotion, skip if class has no property defined
|
||||
return $properties === [];
|
||||
}
|
||||
foreach ($params as $param) {
|
||||
// has non-property promotion, skip
|
||||
if (!$this->visibilityManipulator->hasVisibility($param, \Rector\Core\ValueObject\Visibility::READONLY)) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
return $this->shouldSkipParams($params);
|
||||
}
|
||||
/**
|
||||
* @param Property[] $properties
|
||||
|
@ -151,4 +142,35 @@ CODE_SAMPLE
|
|||
}
|
||||
return \false;
|
||||
}
|
||||
private function shouldSkipClass(\PhpParser\Node\Stmt\Class_ $class) : bool
|
||||
{
|
||||
// need to have test fixture once feature added to nikic/PHP-Parser
|
||||
if ($this->visibilityManipulator->hasVisibility($class, \Rector\Core\ValueObject\Visibility::READONLY)) {
|
||||
return \true;
|
||||
}
|
||||
if ($this->classAnalyzer->isAnonymousClass($class)) {
|
||||
return \true;
|
||||
}
|
||||
if (!$class->isFinal()) {
|
||||
return \true;
|
||||
}
|
||||
return $this->phpAttributeAnalyzer->hasPhpAttribute($class, self::ATTRIBUTE);
|
||||
}
|
||||
/**
|
||||
* @param Param[] $params
|
||||
*/
|
||||
private function shouldSkipParams(array $params) : bool
|
||||
{
|
||||
foreach ($params as $param) {
|
||||
// has non-property promotion, skip
|
||||
if (!$this->visibilityManipulator->hasVisibility($param, \Rector\Core\ValueObject\Visibility::READONLY)) {
|
||||
return \true;
|
||||
}
|
||||
// type is missing, invalid syntax
|
||||
if ($param->type === null) {
|
||||
return \true;
|
||||
}
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,11 @@ final class VersionResolver
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '3619d8bdaa2f48b04c5af3743c40968d76a49a8a';
|
||||
public const PACKAGE_VERSION = '967279219d369ccb2e85ef1d7b34c4fa2ab60531';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-05-31 09:45:22';
|
||||
public const RELEASE_DATE = '2022-05-31 11:35:03';
|
||||
/**
|
||||
* @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 ComposerAutoloaderInit469925c36c5708076861853c3c415431::getLoader();
|
||||
return ComposerAutoloaderInit41d6a08dd7a9313da1d18e71efa45132::getLoader();
|
||||
|
|
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 ComposerAutoloaderInit469925c36c5708076861853c3c415431
|
||||
class ComposerAutoloaderInit41d6a08dd7a9313da1d18e71efa45132
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,19 +22,19 @@ class ComposerAutoloaderInit469925c36c5708076861853c3c415431
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit469925c36c5708076861853c3c415431', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit41d6a08dd7a9313da1d18e71efa45132', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit469925c36c5708076861853c3c415431', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit41d6a08dd7a9313da1d18e71efa45132', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit469925c36c5708076861853c3c415431::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit41d6a08dd7a9313da1d18e71efa45132::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit469925c36c5708076861853c3c415431::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit41d6a08dd7a9313da1d18e71efa45132::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire469925c36c5708076861853c3c415431($fileIdentifier, $file);
|
||||
composerRequire41d6a08dd7a9313da1d18e71efa45132($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
|
@ -46,7 +46,7 @@ class ComposerAutoloaderInit469925c36c5708076861853c3c415431
|
|||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequire469925c36c5708076861853c3c415431($fileIdentifier, $file)
|
||||
function composerRequire41d6a08dd7a9313da1d18e71efa45132($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit469925c36c5708076861853c3c415431
|
||||
class ComposerStaticInit41d6a08dd7a9313da1d18e71efa45132
|
||||
{
|
||||
public static $files = array (
|
||||
'23c18046f52bef3eea034657bafda50f' => __DIR__ . '/..' . '/symfony/polyfill-php81/bootstrap.php',
|
||||
|
@ -3762,9 +3762,9 @@ class ComposerStaticInit469925c36c5708076861853c3c415431
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit469925c36c5708076861853c3c415431::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit469925c36c5708076861853c3c415431::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit469925c36c5708076861853c3c415431::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit41d6a08dd7a9313da1d18e71efa45132::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit41d6a08dd7a9313da1d18e71efa45132::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit41d6a08dd7a9313da1d18e71efa45132::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
|
@ -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('RectorPrefix20220531\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInit469925c36c5708076861853c3c415431', false) && !interface_exists('ComposerAutoloaderInit469925c36c5708076861853c3c415431', false) && !trait_exists('ComposerAutoloaderInit469925c36c5708076861853c3c415431', false)) {
|
||||
spl_autoload_call('RectorPrefix20220531\ComposerAutoloaderInit469925c36c5708076861853c3c415431');
|
||||
if (!class_exists('ComposerAutoloaderInit41d6a08dd7a9313da1d18e71efa45132', false) && !interface_exists('ComposerAutoloaderInit41d6a08dd7a9313da1d18e71efa45132', false) && !trait_exists('ComposerAutoloaderInit41d6a08dd7a9313da1d18e71efa45132', false)) {
|
||||
spl_autoload_call('RectorPrefix20220531\ComposerAutoloaderInit41d6a08dd7a9313da1d18e71efa45132');
|
||||
}
|
||||
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('RectorPrefix20220531\Helmich\TypoScriptParser\Parser\AST\Statement');
|
||||
|
@ -56,9 +56,9 @@ if (!function_exists('print_node')) {
|
|||
return \RectorPrefix20220531\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequire469925c36c5708076861853c3c415431')) {
|
||||
function composerRequire469925c36c5708076861853c3c415431() {
|
||||
return \RectorPrefix20220531\composerRequire469925c36c5708076861853c3c415431(...func_get_args());
|
||||
if (!function_exists('composerRequire41d6a08dd7a9313da1d18e71efa45132')) {
|
||||
function composerRequire41d6a08dd7a9313da1d18e71efa45132() {
|
||||
return \RectorPrefix20220531\composerRequire41d6a08dd7a9313da1d18e71efa45132(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('scanPath')) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user