diff --git a/rules-tests/TypeDeclaration/Rector/BooleanAnd/BinaryOpNullableToInstanceofRector/Fixture/skip_assign.php.inc b/rules-tests/TypeDeclaration/Rector/BooleanAnd/BinaryOpNullableToInstanceofRector/Fixture/skip_assign.php.inc new file mode 100644 index 00000000000..4da84c219e9 --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/BooleanAnd/BinaryOpNullableToInstanceofRector/Fixture/skip_assign.php.inc @@ -0,0 +1,24 @@ +someClass = $this->get()) && $this->someClass->someMethod()) { + return $this->someClass->someMethod(); + } + + return 'no'; + } + + private function get(): ?SomeInstance + { + return rand(0, 1) ? new SomeInstance() : null; + } +} diff --git a/rules-tests/TypeDeclaration/Rector/BooleanAnd/BinaryOpNullableToInstanceofRector/Fixture/skip_assign2.php.inc b/rules-tests/TypeDeclaration/Rector/BooleanAnd/BinaryOpNullableToInstanceofRector/Fixture/skip_assign2.php.inc new file mode 100644 index 00000000000..c835f01f4fc --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/BooleanAnd/BinaryOpNullableToInstanceofRector/Fixture/skip_assign2.php.inc @@ -0,0 +1,24 @@ +someClass = $this->get()) && $this->someClass->someMethod()) { + return $this->someClass->someMethod(); + } + + return 'no'; + } + + private function get(): ?SomeInstance + { + return rand(0, 1) ? new SomeInstance() : null; + } +} diff --git a/rules/TypeDeclaration/Rector/BooleanAnd/BinaryOpNullableToInstanceofRector.php b/rules/TypeDeclaration/Rector/BooleanAnd/BinaryOpNullableToInstanceofRector.php index 15aafcaab3a..dd5acd94813 100644 --- a/rules/TypeDeclaration/Rector/BooleanAnd/BinaryOpNullableToInstanceofRector.php +++ b/rules/TypeDeclaration/Rector/BooleanAnd/BinaryOpNullableToInstanceofRector.php @@ -6,6 +6,7 @@ use PhpParser\Node; use PhpParser\Node\Expr; +use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\BinaryOp\BooleanAnd; use PhpParser\Node\Expr\BinaryOp\BooleanOr; use PhpParser\Node\Expr\BooleanNot; @@ -70,6 +71,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { + if ($node->left instanceof Assign || $node->right instanceof Assign) { + return null; + } + if ($node instanceof BooleanOr) { return $this->processNegationBooleanOr($node); }