diff --git a/docs/rector_rules_overview.md b/docs/rector_rules_overview.md
index 2cb0bcfcc4d..1f520c8a538 100644
--- a/docs/rector_rules_overview.md
+++ b/docs/rector_rules_overview.md
@@ -1,4 +1,4 @@
-# 415 Rules Overview
+# 414 Rules Overview
@@ -62,7 +62,7 @@
- [Strict](#strict) (6)
-- [Transform](#transform) (31)
+- [Transform](#transform) (30)
- [TypeDeclaration](#typedeclaration) (40)
@@ -665,11 +665,11 @@ Change multiple null compares to ?? queue
{
public function run()
{
-- if (null !== $this->orderItem) {
+- if ($this->orderItem !== null) {
- return $this->orderItem;
- }
-
-- if (null !== $this->orderItemUnit) {
+- if ($this->orderItemUnit !== null) {
- return $this->orderItemUnit;
- }
-
@@ -1383,12 +1383,12 @@ Changes foreach that returns set value to ??
```diff
-foreach ($this->oldToNewFunctions as $oldFunction => $newFunction) {
- if ($currentFunction === $oldFunction) {
-- return $newFunction;
+- innerForeachReturn $newFunction;
- }
-}
-
--return null;
-+return $this->oldToNewFunctions[$currentFunction] ?? null;
+-innerForeachReturn null;
++innerForeachReturn $this->oldToNewFunctions[$currentFunction] ?? null;
```
@@ -7907,46 +7907,6 @@ return static function (RectorConfig $rectorConfig): void {
-### FileGetContentsAndJsonDecodeToStaticCallRector
-
-Merge 2 function calls to static call
-
-:wrench: **configure it!**
-
-- class: [`Rector\Transform\Rector\FunctionLike\FileGetContentsAndJsonDecodeToStaticCallRector`](../rules/Transform/Rector/FunctionLike/FileGetContentsAndJsonDecodeToStaticCallRector.php)
-
-```php
-ruleWithConfiguration(FileGetContentsAndJsonDecodeToStaticCallRector::class, [
- new StaticCallRecipe('FileLoader', 'loadJson'),
- ]);
-};
-```
-
-↓
-
-```diff
- final class SomeClass
- {
- public function load($filePath)
- {
-- $fileGetContents = file_get_contents($filePath);
-- return json_decode($fileGetContents, true);
-+ return FileLoader::loadJson($filePath);
- }
- }
-```
-
-
-
### FuncCallToConstFetchRector
Changes use of function calls to use constants
diff --git a/rules/CodeQuality/Rector/If_/ConsecutiveNullCompareReturnsToNullCoalesceQueueRector.php b/rules/CodeQuality/Rector/If_/ConsecutiveNullCompareReturnsToNullCoalesceQueueRector.php
index 77400e1648f..2d4ecb997fd 100644
--- a/rules/CodeQuality/Rector/If_/ConsecutiveNullCompareReturnsToNullCoalesceQueueRector.php
+++ b/rules/CodeQuality/Rector/If_/ConsecutiveNullCompareReturnsToNullCoalesceQueueRector.php
@@ -6,12 +6,13 @@ namespace Rector\CodeQuality\Rector\If_;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Coalesce;
+use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
+use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\NodeManipulator\IfManipulator;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
-use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -20,14 +21,6 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class ConsecutiveNullCompareReturnsToNullCoalesceQueueRector extends AbstractRector implements MinPhpVersionInterface
{
- /**
- * @var Node[]
- */
- private $nodesToRemove = [];
- /**
- * @var Expr[]
- */
- private $coalescingNodes = [];
/**
* @readonly
* @var \Rector\Core\NodeManipulator\IfManipulator
@@ -44,11 +37,11 @@ class SomeClass
{
public function run()
{
- if (null !== $this->orderItem) {
+ if ($this->orderItem !== null) {
return $this->orderItem;
}
- if (null !== $this->orderItemUnit) {
+ if ($this->orderItemUnit !== null) {
return $this->orderItemUnit;
}
@@ -72,71 +65,74 @@ CODE_SAMPLE
*/
public function getNodeTypes() : array
{
- return [If_::class];
+ return [StmtsAwareInterface::class];
}
/**
- * @param If_ $node
+ * @param StmtsAwareInterface $node
*/
public function refactor(Node $node) : ?Node
{
- $this->reset();
- $currentNode = $node;
- while ($currentNode instanceof Node) {
- if ($currentNode instanceof If_) {
- $comparedNode = $this->ifManipulator->matchIfNotNullReturnValue($currentNode);
- if ($comparedNode instanceof Expr) {
- $this->coalescingNodes[] = $comparedNode;
- $this->nodesToRemove[] = $currentNode;
- $currentNode = $currentNode->getAttribute(AttributeKey::NEXT_NODE);
- continue;
- }
- return null;
- }
- if ($this->isReturnNull($currentNode)) {
- $this->nodesToRemove[] = $currentNode;
- break;
- }
+ if ($node->stmts === null) {
return null;
}
+ $coalescingExprs = [];
+ $ifKeys = [];
+ foreach ($node->stmts as $key => $stmt) {
+ if (!$stmt instanceof If_) {
+ continue;
+ }
+ $comparedExpr = $this->ifManipulator->matchIfNotNullReturnValue($stmt);
+ if (!$comparedExpr instanceof Expr) {
+ continue;
+ }
+ $coalescingExprs[] = $comparedExpr;
+ $ifKeys[] = $key;
+ }
// at least 2 coalescing nodes are needed
- if (\count($this->coalescingNodes) < 2) {
+ if (\count($coalescingExprs) < 2) {
return null;
}
- $this->nodeRemover->removeNodes($this->nodesToRemove);
- return $this->createReturnCoalesceNode($this->coalescingNodes);
+ // remove last return null
+ foreach ($node->stmts as $key => $stmt) {
+ if (\in_array($key, $ifKeys, \true)) {
+ unset($node->stmts[$key]);
+ continue;
+ }
+ if (!$this->isReturnNull($stmt)) {
+ continue;
+ }
+ unset($node->stmts[$key]);
+ }
+ $node->stmts[] = $this->createCealesceReturn($coalescingExprs);
+ return $node;
}
public function provideMinPhpVersion() : int
{
return PhpVersionFeature::NULL_COALESCE;
}
- private function reset() : void
+ private function isReturnNull(Stmt $stmt) : bool
{
- $this->coalescingNodes = [];
- $this->nodesToRemove = [];
- }
- private function isReturnNull(Node $node) : bool
- {
- if (!$node instanceof Return_) {
+ if (!$stmt instanceof Return_) {
return \false;
}
- if (!$node->expr instanceof Expr) {
+ if (!$stmt->expr instanceof Expr) {
return \false;
}
- return $this->valueResolver->isNull($node->expr);
+ return $this->valueResolver->isNull($stmt->expr);
}
/**
- * @param Expr[] $coalescingNodes
+ * @param Expr[] $coalescingExprs
*/
- private function createReturnCoalesceNode(array $coalescingNodes) : Return_
+ private function createCealesceReturn(array $coalescingExprs) : Return_
{
- /** @var Expr $left */
- $left = \array_shift($coalescingNodes);
- /** @var Expr $right */
- $right = \array_shift($coalescingNodes);
- $coalesceNode = new Coalesce($left, $right);
- foreach ($coalescingNodes as $coalescingNode) {
- $coalesceNode = new Coalesce($coalesceNode, $coalescingNode);
+ /** @var Expr $leftExpr */
+ $leftExpr = \array_shift($coalescingExprs);
+ /** @var Expr $rightExpr */
+ $rightExpr = \array_shift($coalescingExprs);
+ $coalesce = new Coalesce($leftExpr, $rightExpr);
+ foreach ($coalescingExprs as $coalescingExpr) {
+ $coalesce = new Coalesce($coalesce, $coalescingExpr);
}
- return new Return_($coalesceNode);
+ return new Return_($coalesce);
}
}
diff --git a/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php b/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php
index 010ff8cbfdf..3ff07be5159 100644
--- a/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php
+++ b/rules/CodingStyle/Rector/Catch_/CatchExceptionNameMatchingTypeRector.php
@@ -90,10 +90,8 @@ CODE_SAMPLE
if (!$node->var instanceof Variable) {
return null;
}
+ /** @var string $oldVariableName */
$oldVariableName = $this->getName($node->var);
- if (!\is_string($oldVariableName)) {
- return null;
- }
$type = $node->types[0];
$typeShortName = $this->nodeNameResolver->getShortName($type);
$aliasName = $this->aliasNameResolver->resolveByName($type);
@@ -101,8 +99,7 @@ CODE_SAMPLE
$typeShortName = $aliasName;
}
$newVariableName = Strings::replace(\lcfirst($typeShortName), self::STARTS_WITH_ABBREVIATION_REGEX, static function (array $matches) : string {
- $output = '';
- $output .= isset($matches[1]) ? \strtolower((string) $matches[1]) : '';
+ $output = isset($matches[1]) ? \strtolower((string) $matches[1]) : '';
$output .= $matches[2] ?? '';
return $output . ($matches[3] ?? '');
});
diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php
index bab0c9c2ea0..2116012f30d 100644
--- a/src/Application/VersionResolver.php
+++ b/src/Application/VersionResolver.php
@@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
- public const PACKAGE_VERSION = '89bc4d80f5dd4c7e81a616c8b58a921a1470a47b';
+ public const PACKAGE_VERSION = '76da9489fe16c5854d5fed29b81197940025e975';
/**
* @api
* @var string
*/
- public const RELEASE_DATE = '2023-05-10 05:14:15';
+ public const RELEASE_DATE = '2023-05-10 06:03:12';
/**
* @var int
*/
diff --git a/vendor/autoload.php b/vendor/autoload.php
index 6f6a89d0dcc..cae2ee289e3 100644
--- a/vendor/autoload.php
+++ b/vendor/autoload.php
@@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
-return ComposerAutoloaderInited13d2d55a7019dfa6e7e16a14385fd2::getLoader();
+return ComposerAutoloaderInit7c96cac68aa678588e9ac8ea243e6ab0::getLoader();
diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php
index 242e7085832..86c3adb0860 100644
--- a/vendor/composer/autoload_real.php
+++ b/vendor/composer/autoload_real.php
@@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
-class ComposerAutoloaderInited13d2d55a7019dfa6e7e16a14385fd2
+class ComposerAutoloaderInit7c96cac68aa678588e9ac8ea243e6ab0
{
private static $loader;
@@ -22,17 +22,17 @@ class ComposerAutoloaderInited13d2d55a7019dfa6e7e16a14385fd2
return self::$loader;
}
- spl_autoload_register(array('ComposerAutoloaderInited13d2d55a7019dfa6e7e16a14385fd2', 'loadClassLoader'), true, true);
+ spl_autoload_register(array('ComposerAutoloaderInit7c96cac68aa678588e9ac8ea243e6ab0', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
- spl_autoload_unregister(array('ComposerAutoloaderInited13d2d55a7019dfa6e7e16a14385fd2', 'loadClassLoader'));
+ spl_autoload_unregister(array('ComposerAutoloaderInit7c96cac68aa678588e9ac8ea243e6ab0', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
- call_user_func(\Composer\Autoload\ComposerStaticInited13d2d55a7019dfa6e7e16a14385fd2::getInitializer($loader));
+ call_user_func(\Composer\Autoload\ComposerStaticInit7c96cac68aa678588e9ac8ea243e6ab0::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
- $filesToLoad = \Composer\Autoload\ComposerStaticInited13d2d55a7019dfa6e7e16a14385fd2::$files;
+ $filesToLoad = \Composer\Autoload\ComposerStaticInit7c96cac68aa678588e9ac8ea243e6ab0::$files;
$requireFile = \Closure::bind(static function ($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 b7dc259937c..026edcf6f9c 100644
--- a/vendor/composer/autoload_static.php
+++ b/vendor/composer/autoload_static.php
@@ -4,7 +4,7 @@
namespace Composer\Autoload;
-class ComposerStaticInited13d2d55a7019dfa6e7e16a14385fd2
+class ComposerStaticInit7c96cac68aa678588e9ac8ea243e6ab0
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@@ -3112,9 +3112,9 @@ class ComposerStaticInited13d2d55a7019dfa6e7e16a14385fd2
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
- $loader->prefixLengthsPsr4 = ComposerStaticInited13d2d55a7019dfa6e7e16a14385fd2::$prefixLengthsPsr4;
- $loader->prefixDirsPsr4 = ComposerStaticInited13d2d55a7019dfa6e7e16a14385fd2::$prefixDirsPsr4;
- $loader->classMap = ComposerStaticInited13d2d55a7019dfa6e7e16a14385fd2::$classMap;
+ $loader->prefixLengthsPsr4 = ComposerStaticInit7c96cac68aa678588e9ac8ea243e6ab0::$prefixLengthsPsr4;
+ $loader->prefixDirsPsr4 = ComposerStaticInit7c96cac68aa678588e9ac8ea243e6ab0::$prefixDirsPsr4;
+ $loader->classMap = ComposerStaticInit7c96cac68aa678588e9ac8ea243e6ab0::$classMap;
}, null, ClassLoader::class);
}