Skip to content

Commit

Permalink
skip on assign
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Jan 6, 2025
1 parent 8a428e0 commit 81f6b45
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 42 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector\Fixture;

class SkipOnAssign
{
public function run(?\DateTimeImmutable $param)
{
if (null === ($paramValue = $param)) {
return 'no';
}

return $paramValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
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 @@ -88,15 +87,15 @@ private function processConvertToExclusiveType(
ObjectType $objectType,
Expr $expr,
Identical|NotIdentical $binaryOp
): BooleanNot|Instanceof_ {
): BooleanNot|Instanceof_|null {
if ($expr instanceof Assign) {
return null;
}

$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;
Expand Down
1 change: 0 additions & 1 deletion rules/DeadCode/Rector/If_/RemoveDeadInstanceOfRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ private function refactorStmtAndInstanceof(If_ $if, Instanceof_ $instanceof): nu
}

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

0 comments on commit 81f6b45

Please sign in to comment.