From 015c053dc707a8943ef2a4ef9d0cc08e11aad4e6 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Tue, 21 Jan 2025 13:19:34 +0000 Subject: [PATCH] Updated Rector to commit 223cb9100889a21bb4e8b2a1aa9583e80e1f22b4 https://github.com/rectorphp/rector-src/commit/223cb9100889a21bb4e8b2a1aa9583e80e1f22b4 [Printer] Move set wrap on assign instanceof to BetterStandardPrinter (#6686) --- ...lipTypeControlToUseExclusiveTypeRector.php | 5 ---- src/Application/VersionResolver.php | 4 +-- .../Printer/BetterStandardPrinter.php | 25 +++++++++++++------ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/rules/CodeQuality/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector.php b/rules/CodeQuality/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector.php index a5446f9a52f..0a0d72e414d 100644 --- a/rules/CodeQuality/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector.php +++ b/rules/CodeQuality/Rector/Identical/FlipTypeControlToUseExclusiveTypeRector.php @@ -5,14 +5,12 @@ namespace Rector\CodeQuality\Rector\Identical; use PhpParser\Node; use PhpParser\Node\Expr; -use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\BinaryOp\Identical; use PhpParser\Node\Expr\BinaryOp\NotIdentical; use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\Instanceof_; use PhpParser\Node\Name\FullyQualified; use PHPStan\Type\ObjectType; -use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\PhpParser\Node\Value\ValueResolver; use Rector\Rector\AbstractRector; use Rector\StaticTypeMapper\ValueObject\Type\AliasedObjectType; @@ -87,9 +85,6 @@ CODE_SAMPLE private function processConvertToExclusiveType(ObjectType $objectType, Expr $expr, $binaryOp) { $fullyQualifiedType = $objectType instanceof ShortenedObjectType || $objectType instanceof AliasedObjectType ? $objectType->getFullyQualifiedName() : $objectType->getClassName(); - if ($expr instanceof Assign) { - $expr->setAttribute(AttributeKey::WRAPPED_IN_PARENTHESES, \true); - } $instanceof = new Instanceof_($expr, new FullyQualified($fullyQualifiedType)); if ($binaryOp instanceof NotIdentical) { return $instanceof; diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 1cc7cd5d5f9..42832417571 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 = 'e4e77b2fe9ddefec46aeea5b18ea90ade7188874'; + public const PACKAGE_VERSION = '223cb9100889a21bb4e8b2a1aa9583e80e1f22b4'; /** * @api * @var string */ - public const RELEASE_DATE = '2025-01-21 19:26:17'; + public const RELEASE_DATE = '2025-01-21 20:17:09'; /** * @var int */ diff --git a/src/PhpParser/Printer/BetterStandardPrinter.php b/src/PhpParser/Printer/BetterStandardPrinter.php index e188332f817..56a38e5b1ed 100644 --- a/src/PhpParser/Printer/BetterStandardPrinter.php +++ b/src/PhpParser/Printer/BetterStandardPrinter.php @@ -13,6 +13,7 @@ use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\CallLike; +use PhpParser\Node\Expr\Instanceof_; use PhpParser\Node\Expr\Match_; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\Ternary; @@ -319,16 +320,26 @@ final class BetterStandardPrinter extends Standard } protected function pInfixOp(string $class, Node $leftNode, string $operatorString, Node $rightNode, int $precedence, int $lhsPrecedence) : string { - /** - * ensure left side is assign and right side is just created - * - * @see https://github.com/rectorphp/rector-src/pull/6668 - * @see https://github.com/rectorphp/rector/issues/8980 - */ + $this->wrapAssign($leftNode, $rightNode); + return parent::pInfixOp($class, $leftNode, $operatorString, $rightNode, $precedence, $lhsPrecedence); + } + protected function pExpr_Instanceof(Instanceof_ $instanceof, int $precedence, int $lhsPrecedence) : string + { + $this->wrapAssign($instanceof->expr, $instanceof->class); + return parent::pExpr_Instanceof($instanceof, $precedence, $lhsPrecedence); + } + /** + * ensure left side is assign and right side is just created + * + * @see https://github.com/rectorphp/rector-src/pull/6668 + * @see https://github.com/rectorphp/rector/issues/8980 + * @see https://github.com/rectorphp/rector-src/pull/6653 + */ + private function wrapAssign(Node $leftNode, Node $rightNode) : void + { if ($leftNode instanceof Assign && $leftNode->getStartTokenPos() > 0 && $rightNode->getStartTokenPos() < 0) { $leftNode->setAttribute(AttributeKey::WRAPPED_IN_PARENTHESES, \true); } - return parent::pInfixOp($class, $leftNode, $operatorString, $rightNode, $precedence, $lhsPrecedence); } private function cleanStartIndentationOnHeredocNowDoc(string $content) : string {