mirror of https://github.com/rectorphp/rector.git
Updated Rector to commit e6048295f9001e693403f9f47fd956c543636c16
e6048295f9
[DeadCode] Use flag on return ClassMethod node on RemoveUnusedConstructorParamRector (#4017)
This commit is contained in:
parent
672507859d
commit
6b379fd240
|
@ -92,18 +92,19 @@ CODE_SAMPLE
|
|||
private function processRemoveParams(ClassMethod $classMethod) : ?ClassMethod
|
||||
{
|
||||
$paramKeysToBeRemoved = [];
|
||||
$totalParams = $classMethod->params;
|
||||
foreach ($classMethod->params as $key => $param) {
|
||||
if ($this->paramAnalyzer->isParamUsedInClassMethod($classMethod, $param)) {
|
||||
continue;
|
||||
}
|
||||
$paramKeysToBeRemoved[] = $key;
|
||||
}
|
||||
$this->complexNodeRemover->processRemoveParamWithKeys($classMethod, $paramKeysToBeRemoved);
|
||||
$newTotalParams = $classMethod->params;
|
||||
if ($totalParams === $newTotalParams) {
|
||||
if ($paramKeysToBeRemoved === []) {
|
||||
return null;
|
||||
}
|
||||
return $classMethod;
|
||||
$hasRemoved = $this->complexNodeRemover->processRemoveParamWithKeys($classMethod, $paramKeysToBeRemoved);
|
||||
if ($hasRemoved) {
|
||||
return $classMethod;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -165,25 +165,28 @@ final class ComplexNodeRemover
|
|||
/**
|
||||
* @param int[] $paramKeysToBeRemoved
|
||||
*/
|
||||
public function processRemoveParamWithKeys(ClassMethod $classMethod, array $paramKeysToBeRemoved) : void
|
||||
public function processRemoveParamWithKeys(ClassMethod $classMethod, array $paramKeysToBeRemoved) : bool
|
||||
{
|
||||
$totalKeys = \count($classMethod->params) - 1;
|
||||
$hasRemoved = \false;
|
||||
foreach ($paramKeysToBeRemoved as $paramKeyToBeRemoved) {
|
||||
$startNextKey = $paramKeyToBeRemoved + 1;
|
||||
for ($nextKey = $startNextKey; $nextKey <= $totalKeys; ++$nextKey) {
|
||||
if (!isset($classMethod->params[$nextKey])) {
|
||||
// no next param, break the inner loop, remove the param
|
||||
unset($classMethod->params[$paramKeyToBeRemoved]);
|
||||
return;
|
||||
return \true;
|
||||
}
|
||||
if (\in_array($nextKey, $paramKeysToBeRemoved, \true)) {
|
||||
// keep searching next key not in $paramKeysToBeRemoved
|
||||
continue;
|
||||
}
|
||||
return;
|
||||
return $hasRemoved;
|
||||
}
|
||||
unset($classMethod->params[$paramKeyToBeRemoved]);
|
||||
$hasRemoved = \true;
|
||||
}
|
||||
return $hasRemoved;
|
||||
}
|
||||
/**
|
||||
* @return StaticPropertyFetch[]|PropertyFetch[]
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '580c76d7fe50f608dfac67f011cd6cac33b6ef72';
|
||||
public const PACKAGE_VERSION = 'e6048295f9001e693403f9f47fd956c543636c16';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-05-29 12:01:44';
|
||||
public const RELEASE_DATE = '2023-05-29 12:12:16';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitcb446707078fddb000fece011f701c5c::getLoader();
|
||||
return ComposerAutoloaderInit54644d00b704450b22a86b171867cc03::getLoader();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInitcb446707078fddb000fece011f701c5c
|
||||
class ComposerAutoloaderInit54644d00b704450b22a86b171867cc03
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInitcb446707078fddb000fece011f701c5c
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitcb446707078fddb000fece011f701c5c', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit54644d00b704450b22a86b171867cc03', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitcb446707078fddb000fece011f701c5c', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit54644d00b704450b22a86b171867cc03', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitcb446707078fddb000fece011f701c5c::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit54644d00b704450b22a86b171867cc03::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInitcb446707078fddb000fece011f701c5c::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit54644d00b704450b22a86b171867cc03::$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 ComposerStaticInitcb446707078fddb000fece011f701c5c
|
||||
class ComposerStaticInit54644d00b704450b22a86b171867cc03
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -3083,9 +3083,9 @@ class ComposerStaticInitcb446707078fddb000fece011f701c5c
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitcb446707078fddb000fece011f701c5c::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitcb446707078fddb000fece011f701c5c::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitcb446707078fddb000fece011f701c5c::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit54644d00b704450b22a86b171867cc03::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit54644d00b704450b22a86b171867cc03::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit54644d00b704450b22a86b171867cc03::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
|
@ -821,17 +821,17 @@
|
|||
},
|
||||
{
|
||||
"name": "phpstan\/phpdoc-parser",
|
||||
"version": "1.21.0",
|
||||
"version_normalized": "1.21.0.0",
|
||||
"version": "1.21.1",
|
||||
"version_normalized": "1.21.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https:\/\/github.com\/phpstan\/phpdoc-parser.git",
|
||||
"reference": "6df62b08faef4f899772bc7c3bbabb93d2b7a21c"
|
||||
"reference": "e560a3eb5e76b35d6d92377e5abb6887c1c13c95"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpdoc-parser\/zipball\/6df62b08faef4f899772bc7c3bbabb93d2b7a21c",
|
||||
"reference": "6df62b08faef4f899772bc7c3bbabb93d2b7a21c",
|
||||
"url": "https:\/\/api.github.com\/repos\/phpstan\/phpdoc-parser\/zipball\/e560a3eb5e76b35d6d92377e5abb6887c1c13c95",
|
||||
"reference": "e560a3eb5e76b35d6d92377e5abb6887c1c13c95",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -847,7 +847,7 @@
|
|||
"phpunit\/phpunit": "^9.5",
|
||||
"symfony\/process": "^5.2"
|
||||
},
|
||||
"time": "2023-05-17T13:13:44+00:00",
|
||||
"time": "2023-05-29T11:55:57+00:00",
|
||||
"type": "library",
|
||||
"installation-source": "dist",
|
||||
"autoload": {
|
||||
|
@ -864,7 +864,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.21.0"
|
||||
"source": "https:\/\/github.com\/phpstan\/phpdoc-parser\/tree\/1.21.1"
|
||||
},
|
||||
"install-path": "..\/phpstan\/phpdoc-parser"
|
||||
},
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -91,12 +91,13 @@ $phpDocNode = $phpDocParser->parse($tokens); // PhpDocNode
|
|||
$cloningTraverser = new NodeTraverser([new CloningVisitor()]);
|
||||
|
||||
/** @var PhpDocNode $newPhpDocNode */
|
||||
$printer = new Printer();
|
||||
[$newPhpDocNode] = $cloningTraverser->traverse([$phpDocNode]);
|
||||
|
||||
// change something in $newPhpDocNode
|
||||
$newPhpDocNode->getParamTagValues()[0]->type = new IdentifierTypeNode('Ipsum');
|
||||
|
||||
// print changed PHPDoc
|
||||
$printer = new Printer();
|
||||
$newPhpDoc = $printer->printFormatPreserving($newPhpDocNode, $phpDocNode, $tokens);
|
||||
echo $newPhpDoc; // '/** @param Ipsum $a */'
|
||||
```
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0"?>
|
||||
<ruleset name="PHPStan Extensions Coding Standard">
|
||||
<config name="php_version" value="70200"/>
|
||||
<arg name="colors"/>
|
||||
<arg name="extensions" value="php"/>
|
||||
<arg name="encoding" value="utf-8"/>
|
||||
<arg name="tab-width" value="4"/>
|
||||
<arg name="cache" value="tmp/phpcs"/>
|
||||
<arg value="sp"/>
|
||||
|
||||
<rule ref="build-cs/phpcs.xml">
|
||||
<exclude name="Squiz.Strings.DoubleQuoteUsage.ContainsVar"/>
|
||||
</rule>
|
||||
<rule ref="SlevomatCodingStandard.Files.TypeNameMatchesFileName">
|
||||
<properties>
|
||||
<property name="rootNamespaces" type="array">
|
||||
<element key="src" value="PHPStan\PhpDocParser"/>
|
||||
<element key="tests/PHPStan" value="PHPStan\PhpDocParser"/>
|
||||
</property>
|
||||
</properties>
|
||||
</rule>
|
||||
</ruleset>
|
|
@ -401,7 +401,7 @@ final class Printer
|
|||
}
|
||||
$delayedAdd = [];
|
||||
}
|
||||
$parenthesesNeeded = isset($this->parenthesesListMap[$mapKey]) && in_array(get_class($newNode), $this->parenthesesListMap[$mapKey], \true);
|
||||
$parenthesesNeeded = isset($this->parenthesesListMap[$mapKey]) && in_array(get_class($newNode), $this->parenthesesListMap[$mapKey], \true) && !in_array(get_class($originalNode), $this->parenthesesListMap[$mapKey], \true);
|
||||
$addParentheses = $parenthesesNeeded && !$originalTokens->hasParentheses($itemStartPos, $itemEndPos);
|
||||
if ($addParentheses) {
|
||||
$result .= '(';
|
||||
|
|
Loading…
Reference in New Issue