-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: TernaryOperatorSpacesFixer
- handle instanceof static
#8879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: TernaryOperatorSpacesFixer
- handle instanceof static
#8879
Conversation
NullableTypeDeclarationFixer
- handle instanceof static
NullableTypeTransformer
- handle instanceof static
NullableTypeTransformer
- handle instanceof static
NullableTypeTransformer
- handle instanceof static
NullableTypeTransformer
- handle instanceof static
TernaryOperatorSpacesFixer
- handle instanceof static
|
||
if ( | ||
$tokens[$prevIndex]->isGivenKind(\T_STATIC) | ||
&& $tokens[$tokens->getPrevMeaningfulToken($prevIndex)]->isGivenKind(\T_INSTANCEOF) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any case that justifies this line (with T_INSTANCEOF
?
If not, I'd say let's add T_STATIC
to self::TYPES
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
T_STATIC
is already part of self::TYPES
, but it needs extra handling because in the sequence static ?
the ?
is not always the "nullable type".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So at the moment the ?
token in $a instanceof static ? $b : $c
is wrongly transformed into CT::T_NULLABLE_TYPE
. This is fixed here.
@@ -82,6 +82,11 @@ function A(){} | |||
echo $guard?1:2;}', | |||
]; | |||
|
|||
yield 'handle instanceof static' => [ | |||
'<?php $a instanceof static ? $b : $c;', | |||
'<?php $a instanceof static?$b:$c;', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this wasn't fixed before.
@@ -41,6 +41,10 @@ public function testFix(string $expected, ?string $input = null): void | |||
*/ | |||
public static function provideFixCases(): iterable | |||
{ | |||
yield [ | |||
'<?php $a instanceof static ? \DateTime::class : $c;', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was wrongly changed to:
<?php $a instanceof static ?\DateTime::class : $c;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my bad. I got confused that ?
in static ?
is sometimes a nullable type as well.
No description provided.