mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit f87827ca264302c24015bc9d2a27a4a288a05682
f87827ca26
Implement (#3430)
This commit is contained in:
parent
bd50266270
commit
e27f3e5b0b
|
@ -1,4 +1,4 @@
|
|||
# 412 Rules Overview
|
||||
# 413 Rules Overview
|
||||
|
||||
<br>
|
||||
|
||||
|
@ -60,7 +60,7 @@
|
|||
|
||||
- [Restoration](#restoration) (4)
|
||||
|
||||
- [Strict](#strict) (5)
|
||||
- [Strict](#strict) (6)
|
||||
|
||||
- [Transform](#transform) (34)
|
||||
|
||||
|
@ -7526,6 +7526,27 @@ Rename file to respect class name
|
|||
|
||||
## Strict
|
||||
|
||||
### AddConstructorParentCallRector
|
||||
|
||||
Fixer for PHPStan reports by strict type rule - "PHPStan\Rules\Classes\RequireParentConstructCallRule"
|
||||
|
||||
- class: [`Rector\Strict\Rector\ClassMethod\AddConstructorParentCallRector`](../rules/Strict/Rector/ClassMethod/AddConstructorParentCallRector.php)
|
||||
|
||||
```diff
|
||||
class SunshineCommand extends ParentClassWithConstructor
|
||||
{
|
||||
- public function __construct()
|
||||
+ public function __construct(ParentDependency $parentDependency)
|
||||
{
|
||||
$value = 5;
|
||||
+
|
||||
+ parent::__construct($parentDependency);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
### BooleanInBooleanNotRuleFixerRector
|
||||
|
||||
Fixer for PHPStan reports by strict type rule - "PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule"
|
||||
|
|
|
@ -0,0 +1,105 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Strict\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassLike;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use Rector\Core\Enum\ObjectReference;
|
||||
use Rector\Core\NodeManipulator\Dependency\DependencyClassMethodDecorator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* Fixer Rector for PHPStan rule:
|
||||
* https://github.com/phpstan/phpstan-strict-rules/blob/b7dd96a5503919a43b3cd06a2dced9d4252492f2/src/Rules/Classes/RequireParentConstructCallRule.php
|
||||
*
|
||||
* @see \Rector\Tests\Strict\Rector\ClassMethod\AddConstructorParentCallRector\AddConstructorParentCallRectorTest
|
||||
*/
|
||||
final class AddConstructorParentCallRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\NodeManipulator\Dependency\DependencyClassMethodDecorator
|
||||
*/
|
||||
private $dependencyClassMethodDecorator;
|
||||
public function __construct(DependencyClassMethodDecorator $dependencyClassMethodDecorator)
|
||||
{
|
||||
$this->dependencyClassMethodDecorator = $dependencyClassMethodDecorator;
|
||||
}
|
||||
public function getRuleDefinition() : RuleDefinition
|
||||
{
|
||||
$errorMessage = \sprintf('Fixer for PHPStan reports by strict type rule - "%s"', 'PHPStan\\Rules\\Classes\\RequireParentConstructCallRule');
|
||||
return new RuleDefinition($errorMessage, [new CodeSample(<<<'CODE_SAMPLE'
|
||||
class SunshineCommand extends ParentClassWithConstructor
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$value = 5;
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SunshineCommand extends ParentClassWithConstructor
|
||||
{
|
||||
public function __construct(ParentDependency $parentDependency)
|
||||
{
|
||||
$value = 5;
|
||||
|
||||
parent::__construct($parentDependency);
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
/**
|
||||
* @param ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node) : ?Node
|
||||
{
|
||||
$class = $this->betterNodeFinder->findParentType($node, ClassLike::class);
|
||||
if (!$class instanceof Class_) {
|
||||
return null;
|
||||
}
|
||||
if (!$this->isName($node, MethodName::CONSTRUCT)) {
|
||||
return null;
|
||||
}
|
||||
$scope = $node->getAttribute(AttributeKey::SCOPE);
|
||||
if (!$scope instanceof Scope) {
|
||||
return null;
|
||||
}
|
||||
if ($this->hasParentCallOfMethod($node)) {
|
||||
return null;
|
||||
}
|
||||
$this->dependencyClassMethodDecorator->decorateConstructorWithParentDependencies($class, $node, $scope);
|
||||
return $node;
|
||||
}
|
||||
/**
|
||||
* Looks for "parent::__construct"
|
||||
*/
|
||||
private function hasParentCallOfMethod(ClassMethod $classMethod) : bool
|
||||
{
|
||||
return (bool) $this->betterNodeFinder->findFirst((array) $classMethod->stmts, function (Node $node) : bool {
|
||||
if (!$node instanceof StaticCall) {
|
||||
return \false;
|
||||
}
|
||||
if (!$this->isName($node->class, ObjectReference::PARENT)) {
|
||||
return \false;
|
||||
}
|
||||
return $this->isName($node->name, MethodName::CONSTRUCT);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '9d33ac92be2ac793d06d2da7f13a2008544d8d30';
|
||||
public const PACKAGE_VERSION = 'f87827ca264302c24015bc9d2a27a4a288a05682';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-03-09 14:20:05';
|
||||
public const RELEASE_DATE = '2023-03-10 05:42:59';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -95,12 +95,16 @@ final class DependencyClassMethodDecorator
|
|||
if ($param->default !== null) {
|
||||
break;
|
||||
}
|
||||
$paramsWithoutDefaultValue[] = $param;
|
||||
$paramsWithoutDefaultValue[] = clone $param;
|
||||
}
|
||||
$cleanParams = $this->cleanParamsFromVisibilityAndAttributes($paramsWithoutDefaultValue);
|
||||
$cleanParamsToAdd = $this->removeAlreadyPresentParams($cleanParams, $classMethod->params);
|
||||
// replicate parent parameters
|
||||
if ($cleanParamsToAdd !== []) {
|
||||
foreach ($cleanParamsToAdd as $toAdd) {
|
||||
$paramName = $this->nodeNameResolver->getName($toAdd);
|
||||
$this->incrementParamIfExists($toAdd, $paramName, $cleanParamsToAdd, $classMethod->params);
|
||||
}
|
||||
$classMethod->params = \array_merge($cleanParamsToAdd, $classMethod->params);
|
||||
}
|
||||
$staticCall = $this->nodeFactory->createParentConstructWithParams($cleanParams);
|
||||
|
@ -146,6 +150,38 @@ final class DependencyClassMethodDecorator
|
|||
return \true;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* @param Param[] $newParams
|
||||
* @param Param[] $originalParams
|
||||
*/
|
||||
private function incrementParamIfExists(Param $paramToAdd, string $newName, array $newParams, array $originalParams, int $count = 0) : void
|
||||
{
|
||||
$name = $newName;
|
||||
if ($count > 0) {
|
||||
$name .= $count;
|
||||
}
|
||||
foreach ($newParams as $param) {
|
||||
if ($paramToAdd === $param) {
|
||||
continue;
|
||||
}
|
||||
if ($this->nodeNameResolver->isName($param, $name)) {
|
||||
++$count;
|
||||
$this->incrementParamIfExists($paramToAdd, $newName, $newParams, $originalParams, $count);
|
||||
return;
|
||||
}
|
||||
}
|
||||
foreach ($originalParams as $param) {
|
||||
if ($this->nodeNameResolver->isName($param, $name)) {
|
||||
++$count;
|
||||
$this->incrementParamIfExists($paramToAdd, $newName, $newParams, $originalParams, $count);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ($name !== $newName) {
|
||||
$paramToAdd->var = clone $paramToAdd->var;
|
||||
$paramToAdd->var->name = $name;
|
||||
}
|
||||
}
|
||||
private function areMaybeTypesEqual(?Type $type1, ?Type $type2) : bool
|
||||
{
|
||||
if ($type1 === null) {
|
||||
|
|
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit6ed4f2a44f7f1df1cfe6450077b6111f::getLoader();
|
||||
return ComposerAutoloaderInit3566f28bef0f2b69c6833c4925822be9::getLoader();
|
||||
|
|
|
@ -2514,6 +2514,7 @@ return array(
|
|||
'Rector\\Strict\\NodeFactory\\ExactCompareFactory' => $baseDir . '/rules/Strict/NodeFactory/ExactCompareFactory.php',
|
||||
'Rector\\Strict\\Rector\\AbstractFalsyScalarRuleFixerRector' => $baseDir . '/rules/Strict/Rector/AbstractFalsyScalarRuleFixerRector.php',
|
||||
'Rector\\Strict\\Rector\\BooleanNot\\BooleanInBooleanNotRuleFixerRector' => $baseDir . '/rules/Strict/Rector/BooleanNot/BooleanInBooleanNotRuleFixerRector.php',
|
||||
'Rector\\Strict\\Rector\\ClassMethod\\AddConstructorParentCallRector' => $baseDir . '/rules/Strict/Rector/ClassMethod/AddConstructorParentCallRector.php',
|
||||
'Rector\\Strict\\Rector\\Empty_\\DisallowedEmptyRuleFixerRector' => $baseDir . '/rules/Strict/Rector/Empty_/DisallowedEmptyRuleFixerRector.php',
|
||||
'Rector\\Strict\\Rector\\If_\\BooleanInIfConditionRuleFixerRector' => $baseDir . '/rules/Strict/Rector/If_/BooleanInIfConditionRuleFixerRector.php',
|
||||
'Rector\\Strict\\Rector\\Ternary\\BooleanInTernaryOperatorRuleFixerRector' => $baseDir . '/rules/Strict/Rector/Ternary/BooleanInTernaryOperatorRuleFixerRector.php',
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit6ed4f2a44f7f1df1cfe6450077b6111f
|
||||
class ComposerAutoloaderInit3566f28bef0f2b69c6833c4925822be9
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInit6ed4f2a44f7f1df1cfe6450077b6111f
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit6ed4f2a44f7f1df1cfe6450077b6111f', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit3566f28bef0f2b69c6833c4925822be9', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit6ed4f2a44f7f1df1cfe6450077b6111f', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit3566f28bef0f2b69c6833c4925822be9', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit6ed4f2a44f7f1df1cfe6450077b6111f::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit3566f28bef0f2b69c6833c4925822be9::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit6ed4f2a44f7f1df1cfe6450077b6111f::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit3566f28bef0f2b69c6833c4925822be9::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit6ed4f2a44f7f1df1cfe6450077b6111f
|
||||
class ComposerStaticInit3566f28bef0f2b69c6833c4925822be9
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -2766,6 +2766,7 @@ class ComposerStaticInit6ed4f2a44f7f1df1cfe6450077b6111f
|
|||
'Rector\\Strict\\NodeFactory\\ExactCompareFactory' => __DIR__ . '/../..' . '/rules/Strict/NodeFactory/ExactCompareFactory.php',
|
||||
'Rector\\Strict\\Rector\\AbstractFalsyScalarRuleFixerRector' => __DIR__ . '/../..' . '/rules/Strict/Rector/AbstractFalsyScalarRuleFixerRector.php',
|
||||
'Rector\\Strict\\Rector\\BooleanNot\\BooleanInBooleanNotRuleFixerRector' => __DIR__ . '/../..' . '/rules/Strict/Rector/BooleanNot/BooleanInBooleanNotRuleFixerRector.php',
|
||||
'Rector\\Strict\\Rector\\ClassMethod\\AddConstructorParentCallRector' => __DIR__ . '/../..' . '/rules/Strict/Rector/ClassMethod/AddConstructorParentCallRector.php',
|
||||
'Rector\\Strict\\Rector\\Empty_\\DisallowedEmptyRuleFixerRector' => __DIR__ . '/../..' . '/rules/Strict/Rector/Empty_/DisallowedEmptyRuleFixerRector.php',
|
||||
'Rector\\Strict\\Rector\\If_\\BooleanInIfConditionRuleFixerRector' => __DIR__ . '/../..' . '/rules/Strict/Rector/If_/BooleanInIfConditionRuleFixerRector.php',
|
||||
'Rector\\Strict\\Rector\\Ternary\\BooleanInTernaryOperatorRuleFixerRector' => __DIR__ . '/../..' . '/rules/Strict/Rector/Ternary/BooleanInTernaryOperatorRuleFixerRector.php',
|
||||
|
@ -3132,9 +3133,9 @@ class ComposerStaticInit6ed4f2a44f7f1df1cfe6450077b6111f
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit6ed4f2a44f7f1df1cfe6450077b6111f::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit6ed4f2a44f7f1df1cfe6450077b6111f::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit6ed4f2a44f7f1df1cfe6450077b6111f::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit3566f28bef0f2b69c6833c4925822be9::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit3566f28bef0f2b69c6833c4925822be9::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit3566f28bef0f2b69c6833c4925822be9::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
|
@ -869,17 +869,17 @@
|
|||
},
|
||||
{
|
||||
"name": "phpstan\/phpstan",
|
||||
"version": "1.10.5",
|
||||
"version_normalized": "1.10.5.0",
|
||||
"version": "1.10.6",
|
||||
"version_normalized": "1.10.6.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/phpstan\/phpstan.git",
|
||||
"reference": "1fb6f494d82455151ecf15c5c191923f5d84324e"
|
||||
"reference": "50d089a3e0904b0fe7e2cf2d4fd37d427d64235a"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpstan\/zipball\/1fb6f494d82455151ecf15c5c191923f5d84324e",
|
||||
"reference": "1fb6f494d82455151ecf15c5c191923f5d84324e",
|
||||
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpstan\/zipball\/50d089a3e0904b0fe7e2cf2d4fd37d427d64235a",
|
||||
"reference": "50d089a3e0904b0fe7e2cf2d4fd37d427d64235a",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -888,7 +888,7 @@
|
|||
"conflict": {
|
||||
"phpstan\/phpstan-shim": "*"
|
||||
},
|
||||
"time": "2023-03-07T16:48:45+00:00",
|
||||
"time": "2023-03-09T16:55:12+00:00",
|
||||
"bin": [
|
||||
"phpstan",
|
||||
"phpstan.phar"
|
||||
|
@ -911,7 +911,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https:\/\/github.com\/phpstan\/phpstan\/issues",
|
||||
"source": "https:\/\/github.com\/phpstan\/phpstan\/tree\/1.10.5"
|
||||
"source": "https:\/\/github.com\/phpstan\/phpstan\/tree\/1.10.6"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
|
File diff suppressed because one or more lines are too long
Binary file not shown.
|
@ -1,16 +1,16 @@
|
|||
-----BEGIN PGP SIGNATURE-----
|
||||
|
||||
iQIzBAABCgAdFiEE0yaA1ZV9xxFr4pwUzxoQjQ565yAFAmQHatYACgkQzxoQjQ56
|
||||
5yAU7A/8CLVE46kub8QEP/s8/w9T4uOyG1vsFwv9dafa4PySyvhZCr/vliCuYyF9
|
||||
JUUSXqyGIFi+VKsuY8y7u5zaVqpq6O6qJBkzsUK/X9BHZfFEo1k2v/NNJD7t3p0b
|
||||
or5u9bOTlSJnXV+1hPNjkW4wcnxR6kuJQIoz9XwNsQC07mPVxNrHknxnkgGFVDNR
|
||||
ITjpW3rBW3vRtoOWajPJMXZt6f+pJCl8ccISK97gskAzK75t2Ymle9fV9FdQYGWt
|
||||
8X/gfQtVfJOkEmHV6F+pUE9o++aNCPljNo1O+1eS62TTOSRlS6fNhppu/o7Z4IIi
|
||||
9QS3DHhDTGQPLUCXbMToK/kwRCAzDe9lFgjpKIUQhmEGKOjTNup2NPqWGtQNQj7h
|
||||
WTP6W2GNpGh5g+d7Tm667FKej/AgixwvpdJqR1VGk2PI2EYMryMz17nQ1cvGinOW
|
||||
X3auWZe/HWuyqFtt5r85ffZGVS/4xKxeAK85HPrn3mzotiXr/KZf8S525BuGqUaZ
|
||||
lQ7paCM6kZ9rn9vMmLEe57Ypl7bMzfUV6c2k5KYYR2EV9LXzNPS9G7Yhpg/Q3G2S
|
||||
cTqxKuBk+hvXd3rp4OwzrjAUps8w4XzyHBpDl9k1n2oB+1Plygrkew8Z5CRglTL4
|
||||
lSQAD2FLSTEAvPcFi3kkiBxxeoXSSnjP2iruPsAkcfzsENBFTdM=
|
||||
=4/CB
|
||||
iQIzBAABCgAdFiEE0yaA1ZV9xxFr4pwUzxoQjQ565yAFAmQKD1cACgkQzxoQjQ56
|
||||
5yDePQ//ZtI/AKKhBlTvj6I6mw69TBuVi/7y+uU0CyrgKodCJlBCvprybXS2GItU
|
||||
rh2rMrX75IGOx8tEBs/6Ec5BuPF5rIQZdPndsYzT+sH8hBCLCQ/SlgtE/bZ7CIjr
|
||||
/WBkTjXd+T2lGmIe1e57rxNUiy+tgWlEa/mf963lY5Oy5zfuui6HEVzEofGtdq3c
|
||||
l9FSx+9pVX4rCHKZzCy1lNuh3xdHEYS52mMCsYuuOo0GZ9e1cqFBj4VwF9WkLlr5
|
||||
oEvJanpJx32YcYOkhD1tE5N/3Gxtw1AZMSq4onJvts8YyqGA2q7uTDdRmW2yyiB7
|
||||
DgPFrfE2rNGCymU6n04hPhKyMIBk8nJB89qYtInIzbpm7+xPRrt6pKWFGIvAXeNx
|
||||
qDHM3H+efvDadXl47z3aJLsgXxnefI6VJjXJF28mxEmwtm9Jt6tNvzEz+FHDgM11
|
||||
xat1m+oREXArPNA7cDTu5IIQY0BomKKc6H8X/X5OtKoVj0xoXbu/tfLVIJ8XYech
|
||||
oAc+F0eA1k3vNxd5owM3ZaNqAFsGCA0dAgUWm2sNliZZZcnx0pWDvl/CG/Qetktz
|
||||
15DvlfokTtCXPihy4tk1rYh/+EZfrwTJAMg4Xn3t9XlBapLUVH09EoRRi/0cVs9J
|
||||
7x1FBChPFcvMSwrPo+mPzmjTfJ59QCt0BqYk7q/84KtcX85KQlg=
|
||||
=3/5f
|
||||
-----END PGP SIGNATURE-----
|
||||
|
|
Loading…
Reference in New Issue