-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump Symplify to 10.0.16 + improve complexity (#1725)
Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
420dc93
commit caeeb78
Showing
15 changed files
with
198 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\DowngradePhp72\NodeAnalyzer; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr; | ||
use PhpParser\Node\Expr\Assign; | ||
use PhpParser\Node\Expr\FuncCall; | ||
use PhpParser\Node\Expr\Ternary; | ||
use PhpParser\Node\Expr\Variable; | ||
use Rector\Core\PhpParser\Comparing\NodeComparator; | ||
use Rector\Core\PhpParser\Node\BetterNodeFinder; | ||
use Rector\Core\PhpParser\Node\Value\ValueResolver; | ||
use Rector\NodeNameResolver\NodeNameResolver; | ||
|
||
final class RegexFuncAnalyzer | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private const REGEX_FUNCTION_NAMES = ['preg_match', 'preg_match_all']; | ||
|
||
public function __construct( | ||
private readonly NodeNameResolver $nodeNameResolver, | ||
private readonly BetterNodeFinder $betterNodeFinder, | ||
private readonly NodeComparator $nodeComparator, | ||
private readonly ValueResolver $valueResolver, | ||
) { | ||
} | ||
|
||
public function isRegexFunctionNames(FuncCall $funcCall): bool | ||
{ | ||
if ($this->nodeNameResolver->isNames($funcCall, self::REGEX_FUNCTION_NAMES)) { | ||
return true; | ||
} | ||
|
||
$variable = $funcCall->name; | ||
if (! $variable instanceof Variable) { | ||
return false; | ||
} | ||
|
||
/** @var Assign|null $assignExprVariable */ | ||
$assignExprVariable = $this->betterNodeFinder->findFirstPreviousOfNode($funcCall, function (Node $node) use ( | ||
$variable | ||
): bool { | ||
if (! $node instanceof Assign) { | ||
return false; | ||
} | ||
|
||
return $this->nodeComparator->areNodesEqual($node->var, $variable); | ||
}); | ||
|
||
if (! $assignExprVariable instanceof Assign) { | ||
return false; | ||
} | ||
|
||
$expr = $assignExprVariable->expr; | ||
if (! $expr instanceof Ternary) { | ||
return false; | ||
} | ||
|
||
if (! $expr->if instanceof Expr) { | ||
return false; | ||
} | ||
|
||
if (! $this->valueResolver->isValues($expr->if, self::REGEX_FUNCTION_NAMES)) { | ||
return false; | ||
} | ||
|
||
return $this->valueResolver->isValues($expr->else, self::REGEX_FUNCTION_NAMES); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
rules/DowngradePhp72/NodeManipulator/BitwiseFlagCleaner.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\DowngradePhp72\NodeManipulator; | ||
|
||
use PhpParser\Node\Arg; | ||
use PhpParser\Node\Expr; | ||
use PhpParser\Node\Expr\BinaryOp\BitwiseOr; | ||
use PhpParser\Node\Expr\ConstFetch; | ||
use PhpParser\Node\Expr\FuncCall; | ||
use Rector\NodeNameResolver\NodeNameResolver; | ||
|
||
final class BitwiseFlagCleaner | ||
{ | ||
public function __construct( | ||
private readonly NodeNameResolver $nodeNameResolver | ||
) { | ||
} | ||
|
||
public function cleanFuncCall(FuncCall $funcCall, BitwiseOr $bitwiseOr, Expr $expr = null, string $flag): void | ||
{ | ||
if ($bitwiseOr->left instanceof BitwiseOr) { | ||
/** @var BitwiseOr $leftLeft */ | ||
$leftLeft = $bitwiseOr->left; | ||
if ($leftLeft->left instanceof ConstFetch && $this->nodeNameResolver | ||
->isName($leftLeft->left, $flag)) { | ||
$bitwiseOr = new BitwiseOr($leftLeft->right, $bitwiseOr->right); | ||
} | ||
|
||
/** @var BitwiseOr $leftRight */ | ||
$leftRight = $bitwiseOr->left; | ||
if ($leftRight->right instanceof ConstFetch && $this->nodeNameResolver | ||
->isName($leftRight->right, $flag)) { | ||
$bitwiseOr = new BitwiseOr($leftRight->left, $bitwiseOr->right); | ||
} | ||
|
||
if ($bitwiseOr->left instanceof BitwiseOr) { | ||
$this->cleanFuncCall($funcCall, $bitwiseOr->left, $bitwiseOr->right, $flag); | ||
return; | ||
} | ||
} | ||
|
||
if ($expr instanceof Expr) { | ||
$bitwiseOr = new BitwiseOr($bitwiseOr, $expr); | ||
} | ||
|
||
$this->assignThirdArgsValue($funcCall, $bitwiseOr, $flag); | ||
} | ||
|
||
private function assignThirdArgsValue(FuncCall $funcCall, BitwiseOr $bitwiseOr, string $flag): void | ||
{ | ||
if ($bitwiseOr->right instanceof ConstFetch && $this->nodeNameResolver | ||
->isName($bitwiseOr->right, $flag)) { | ||
$bitwiseOr = $bitwiseOr->left; | ||
} elseif ($bitwiseOr->left instanceof ConstFetch && $this->nodeNameResolver | ||
->isName($bitwiseOr->left, $flag)) { | ||
$bitwiseOr = $bitwiseOr->right; | ||
} | ||
|
||
if (! $funcCall->args[3] instanceof Arg) { | ||
return; | ||
} | ||
|
||
$funcCall->args[3]->value = $bitwiseOr; | ||
} | ||
} |
Oops, something went wrong.