mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit ee04ee1dc59ff0a6c3ff5d6558612dce7757a8f2
ee04ee1dc5
Fix multi property default assign (#2986)
This commit is contained in:
parent
6fe76031c4
commit
a018694585
|
@ -7,6 +7,7 @@ use PhpParser\Node;
|
|||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PhpParser\Node\Stmt\PropertyProperty;
|
||||
use Rector\CodeQuality\NodeAnalyzer\ConstructorPropertyDefaultExprResolver;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
|
@ -69,22 +70,34 @@ CODE_SAMPLE
|
|||
return null;
|
||||
}
|
||||
$hasChanged = \false;
|
||||
$propertyProperties = $this->getNonReadonlyPropertyProperty($node);
|
||||
foreach ($defaultPropertyExprAssigns as $defaultPropertyExprAssign) {
|
||||
$property = $node->getProperty($defaultPropertyExprAssign->getPropertyName());
|
||||
if (!$property instanceof Property) {
|
||||
continue;
|
||||
foreach ($propertyProperties as $propertyProperty) {
|
||||
if (!$this->isName($propertyProperty, $defaultPropertyExprAssign->getPropertyName())) {
|
||||
continue;
|
||||
}
|
||||
$propertyProperty->default = $defaultPropertyExprAssign->getDefaultExpr();
|
||||
$hasChanged = \true;
|
||||
$this->removeNode($defaultPropertyExprAssign->getAssignExpression());
|
||||
}
|
||||
if ($property->isReadonly()) {
|
||||
continue;
|
||||
}
|
||||
$propertyProperty = $property->props[0];
|
||||
$propertyProperty->default = $defaultPropertyExprAssign->getDefaultExpr();
|
||||
$hasChanged = \true;
|
||||
$this->removeNode($defaultPropertyExprAssign->getAssignExpression());
|
||||
}
|
||||
if (!$hasChanged) {
|
||||
return null;
|
||||
}
|
||||
return $node;
|
||||
}
|
||||
/**
|
||||
* @return PropertyProperty[]
|
||||
*/
|
||||
private function getNonReadonlyPropertyProperty(Class_ $class) : array
|
||||
{
|
||||
$propertyProperties = [];
|
||||
foreach ($class->getProperties() as $property) {
|
||||
if ($property->isReadonly()) {
|
||||
continue;
|
||||
}
|
||||
$propertyProperties = \array_merge($propertyProperties, $property->props);
|
||||
}
|
||||
return $propertyProperties;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '2427c5a094a39018e0c558482faf218d577e3382';
|
||||
public const PACKAGE_VERSION = 'ee04ee1dc59ff0a6c3ff5d6558612dce7757a8f2';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2022-10-14 11:43:45';
|
||||
public const RELEASE_DATE = '2022-10-14 16:46:51';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -3,10 +3,23 @@
|
|||
// autoload.php @generated by Composer
|
||||
|
||||
if (PHP_VERSION_ID < 50600) {
|
||||
echo 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
|
||||
exit(1);
|
||||
if (!headers_sent()) {
|
||||
header('HTTP/1.1 500 Internal Server Error');
|
||||
}
|
||||
$err = 'Composer 2.3.0 dropped support for autoloading on PHP <5.6 and you are running '.PHP_VERSION.', please upgrade PHP or use Composer 2.2 LTS via "composer self-update --2.2". Aborting.'.PHP_EOL;
|
||||
if (!ini_get('display_errors')) {
|
||||
if (PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg') {
|
||||
fwrite(STDERR, $err);
|
||||
} elseif (!headers_sent()) {
|
||||
echo $err;
|
||||
}
|
||||
}
|
||||
trigger_error(
|
||||
$err,
|
||||
E_USER_ERROR
|
||||
);
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit7801c2cd5fb87fbd8521631b02cf69bc::getLoader();
|
||||
return ComposerAutoloaderInit5c1fdb34e3926a7a0bf66efb0dc94722::getLoader();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit7801c2cd5fb87fbd8521631b02cf69bc
|
||||
class ComposerAutoloaderInit5c1fdb34e3926a7a0bf66efb0dc94722
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,19 +22,19 @@ class ComposerAutoloaderInit7801c2cd5fb87fbd8521631b02cf69bc
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit7801c2cd5fb87fbd8521631b02cf69bc', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit5c1fdb34e3926a7a0bf66efb0dc94722', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit7801c2cd5fb87fbd8521631b02cf69bc', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit5c1fdb34e3926a7a0bf66efb0dc94722', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit7801c2cd5fb87fbd8521631b02cf69bc::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit5c1fdb34e3926a7a0bf66efb0dc94722::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit7801c2cd5fb87fbd8521631b02cf69bc::$files;
|
||||
$includeFiles = \Composer\Autoload\ComposerStaticInit5c1fdb34e3926a7a0bf66efb0dc94722::$files;
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire7801c2cd5fb87fbd8521631b02cf69bc($fileIdentifier, $file);
|
||||
composerRequire5c1fdb34e3926a7a0bf66efb0dc94722($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
|
@ -46,7 +46,7 @@ class ComposerAutoloaderInit7801c2cd5fb87fbd8521631b02cf69bc
|
|||
* @param string $file
|
||||
* @return void
|
||||
*/
|
||||
function composerRequire7801c2cd5fb87fbd8521631b02cf69bc($fileIdentifier, $file)
|
||||
function composerRequire5c1fdb34e3926a7a0bf66efb0dc94722($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit7801c2cd5fb87fbd8521631b02cf69bc
|
||||
class ComposerStaticInit5c1fdb34e3926a7a0bf66efb0dc94722
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -3091,9 +3091,9 @@ class ComposerStaticInit7801c2cd5fb87fbd8521631b02cf69bc
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit7801c2cd5fb87fbd8521631b02cf69bc::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit7801c2cd5fb87fbd8521631b02cf69bc::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit7801c2cd5fb87fbd8521631b02cf69bc::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit5c1fdb34e3926a7a0bf66efb0dc94722::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit5c1fdb34e3926a7a0bf66efb0dc94722::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit5c1fdb34e3926a7a0bf66efb0dc94722::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
|
@ -685,17 +685,17 @@
|
|||
},
|
||||
{
|
||||
"name": "phpstan\/phpdoc-parser",
|
||||
"version": "1.10.0",
|
||||
"version_normalized": "1.10.0.0",
|
||||
"version": "1.11.0",
|
||||
"version_normalized": "1.11.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/phpstan\/phpdoc-parser.git",
|
||||
"reference": "87fa2d526e56737a2ae8fa201a61b15efae59b8a"
|
||||
"reference": "7d1e81213b0c7eb8d5a9f524456cbc2778ed5c65"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpdoc-parser\/zipball\/87fa2d526e56737a2ae8fa201a61b15efae59b8a",
|
||||
"reference": "87fa2d526e56737a2ae8fa201a61b15efae59b8a",
|
||||
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpdoc-parser\/zipball\/7d1e81213b0c7eb8d5a9f524456cbc2778ed5c65",
|
||||
"reference": "7d1e81213b0c7eb8d5a9f524456cbc2778ed5c65",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -710,7 +710,7 @@
|
|||
"phpunit\/phpunit": "^9.5",
|
||||
"symfony\/process": "^5.2"
|
||||
},
|
||||
"time": "2022-10-12T19:19:18+00:00",
|
||||
"time": "2022-10-14T13:32:28+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
|
@ -727,7 +727,7 @@
|
|||
"description": "PHPDoc parser with support for nullable, intersection and generic types",
|
||||
"support": {
|
||||
"issues": "https:\/\/github.com\/phpstan\/phpdoc-parser\/issues",
|
||||
"source": "https:\/\/github.com\/phpstan\/phpdoc-parser\/tree\/1.10.0"
|
||||
"source": "https:\/\/github.com\/phpstan\/phpdoc-parser\/tree\/1.11.0"
|
||||
},
|
||||
"install-path": "..\/phpstan\/phpdoc-parser"
|
||||
},
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -13,17 +13,21 @@ class TemplateTagValueNode implements \PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTag
|
|||
public $name;
|
||||
/** @var TypeNode|null */
|
||||
public $bound;
|
||||
/** @var TypeNode|null */
|
||||
public $default;
|
||||
/** @var string (may be empty) */
|
||||
public $description;
|
||||
public function __construct(string $name, ?TypeNode $bound, string $description)
|
||||
public function __construct(string $name, ?TypeNode $bound, string $description, ?TypeNode $default = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->bound = $bound;
|
||||
$this->default = $default;
|
||||
$this->description = $description;
|
||||
}
|
||||
public function __toString() : string
|
||||
{
|
||||
$bound = $this->bound !== null ? " of {$this->bound}" : '';
|
||||
return trim("{$this->name}{$bound} {$this->description}");
|
||||
$default = $this->default !== null ? " = {$this->default}" : '';
|
||||
return trim("{$this->name}{$bound}{$default} {$this->description}");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -311,8 +311,13 @@ class PhpDocParser
|
|||
} else {
|
||||
$bound = null;
|
||||
}
|
||||
if ($tokens->tryConsumeTokenValue('=')) {
|
||||
$default = $this->typeParser->parse($tokens);
|
||||
} else {
|
||||
$default = null;
|
||||
}
|
||||
$description = $this->parseOptionalDescription($tokens);
|
||||
return new Ast\PhpDoc\TemplateTagValueNode($name, $bound, $description);
|
||||
return new Ast\PhpDoc\TemplateTagValueNode($name, $bound, $description, $default);
|
||||
}
|
||||
private function parseExtendsTagValue(string $tagName, \PHPStan\PhpDocParser\Parser\TokenIterator $tokens) : Ast\PhpDoc\PhpDocTagValueNode
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue