Skip to content

Commit

Permalink
minor: NoUnneededControlParenthesesFixer - Support instanceof static …
Browse files Browse the repository at this point in the history
…cases (#6587)
  • Loading branch information
SpacePossum authored Aug 26, 2022
1 parent fda8448 commit 52dc232
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ final class NoUnneededControlParenthesesFixer extends AbstractFixer implements C
[T_OBJECT_OPERATOR],
[T_STRING],
[T_VARIABLE],
[T_STATIC],
// magic constants
[T_CLASS_C],
[T_DIR],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,15 @@ function foo() {
$l6 = [1, $foo instanceof Foo, 1];
$fn1 = fn($x) => $fx instanceof Foo;
for ($foo instanceof Foo ; $i < 1; ++$i) { echo $i; }
class foo {
public function bar() {
self instanceof static;
self instanceof self;
$a instanceof static;
self instanceof $a;
$a instanceof self;
}
}
',
'<?php
; ($foo instanceof Foo);
Expand All @@ -1059,6 +1068,15 @@ function foo() {
$l6 = [1, ($foo instanceof Foo), 1];
$fn1 = fn($x) => ($fx instanceof Foo);
for (($foo instanceof Foo) ; $i < 1; ++$i) { echo $i; }
class foo {
public function bar() {
(self instanceof static);
(self instanceof self);
($a instanceof static);
(self instanceof $a);
($a instanceof self);
}
}
',
];

Expand Down Expand Up @@ -1105,6 +1123,29 @@ function foo() {
',
];

yield 'wrapped negative instanceof 2' => [
'<?php
class foo {
public function bar() {
!self instanceof static;
!self instanceof self;
!$a instanceof static;
!self instanceof $a;
!$a instanceof self;
}
}',
'<?php
class foo {
public function bar() {
!(self instanceof static);
!(self instanceof self);
!($a instanceof static);
!(self instanceof $a);
!($a instanceof self);
}
}',
];

yield '(x,y' => [
'<?php $n = ["".foo(1+2),3];',
'<?php $n = [("".foo(1+2)),3];',
Expand Down

0 comments on commit 52dc232

Please sign in to comment.