Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jan 6, 2025
1 parent 616bfed commit 5e9d010
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@

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;
Expand Down Expand Up @@ -91,6 +93,10 @@ private function processConvertToExclusiveType(
? $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;
Expand Down
3 changes: 3 additions & 0 deletions rules/DeadCode/Rector/If_/RemoveDeadInstanceOfRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\DeadCode\Rector\If_;

use Attribute;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
Expand All @@ -22,6 +23,7 @@
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use Rector\NodeManipulator\IfManipulator;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Rector\AbstractRector;
use Rector\Reflection\ReflectionResolver;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down Expand Up @@ -110,6 +112,7 @@ private function refactorStmtAndInstanceof(If_ $if, Instanceof_ $instanceof): nu
}

if ($instanceof->expr instanceof Assign) {
$instanceof->expr->setAttribute(AttributeKey::WRAPPED_IN_PARENTHESES, false);
$assignExpression = new Expression($instanceof->expr);
return array_merge([$assignExpression], $if->stmts);
}
Expand Down

0 comments on commit 5e9d010

Please sign in to comment.