Skip to content

Commit

Permalink
bug #5596 NullableTypeTransformer - fix for attributes (kubawerlos, j…
Browse files Browse the repository at this point in the history
…rmajor)

This PR was merged into the 2.18 branch.

Discussion
----------

NullableTypeTransformer - fix for attributes

Fixes #5533

Commits
-------

86f5b39 Update tests/Fixer/Operator/TernaryToElvisOperatorFixerTest.php
e3f0d37 add test reproducing #5533
62cceb9 Fix
58e6a4d Add failing test case
  • Loading branch information
keradus committed Apr 6, 2021
2 parents 9bf2760 + 86f5b39 commit f01521b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Tokenizer/Transformer/NullableTypeTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function process(Tokens $tokens, Token $token, $index)
[CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC],
[CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED],
[CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE],
[CT::T_ATTRIBUTE_CLOSE],
[T_PRIVATE],
[T_PROTECTED],
[T_PUBLIC],
Expand Down
25 changes: 25 additions & 0 deletions tests/Fixer/Operator/TernaryToElvisOperatorFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,29 @@ public function provideFix70Cases()
],
];
}

/**
* @param string $input
*
* @dataProvider provideDoNotFix80Cases
* @requires PHP 8.0
*/
public function test80DoNotFix($input)
{
$this->doTest($input);
}

public function provideDoNotFix80Cases()
{
return [
['<?php
function test(#[TestAttribute] ?User $user) {}
'],
['<?php
function test(#[TestAttribute] ?User $user = null) {}
'],
];
}
}
8 changes: 8 additions & 0 deletions tests/Tokenizer/Transformer/NullableTypeTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ public function __construct(
41 => CT::T_NULLABLE_TYPE,
],
],
[
'<?php
function test(#[TestAttribute] ?User $user) {}
',
[
10 => CT::T_NULLABLE_TYPE,
],
],
];
}
}

0 comments on commit f01521b

Please sign in to comment.