1
0
mirror of https://github.com/rectorphp/rector.git synced 2025-04-07 09:02:33 +02:00

Updated Rector to commit 223cb9100889a21bb4e8b2a1aa9583e80e1f22b4

223cb91008 [Printer] Move set wrap on assign instanceof to BetterStandardPrinter ()
This commit is contained in:
Tomas Votruba 2025-01-21 13:19:34 +00:00
parent d0a75a7d2c
commit 015c053dc7
3 changed files with 20 additions and 14 deletions
rules/CodeQuality/Rector/Identical
src

@ -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;

@ -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
*/

@ -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
{