Skip to content

Commit

Permalink
minor #5439 VisibilityRequiredFixer - support type alternation for pr…
Browse files Browse the repository at this point in the history
…operties (keradus)

This PR was merged into the 2.17 branch.

Discussion
----------

VisibilityRequiredFixer - support type alternation for properties

Commits
-------

6081f93 VisibilityRequiredFixer - support type alternation for properties
  • Loading branch information
keradus committed Jan 17, 2021
2 parents 6f54ce8 + 6081f93 commit 35997b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Fixer/ClassNotation/VisibilityRequiredFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function createConfigurationDefinition()
protected function applyFix(\SplFileInfo $file, Tokens $tokens)
{
$tokensAnalyzer = new TokensAnalyzer($tokens);
$propertyTypeDeclarationKinds = [T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT];
$propertyTypeDeclarationKinds = [T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, CT::T_TYPE_ALTERNATION];

foreach (array_reverse($tokensAnalyzer->getClassyElements(), true) as $index => $element) {
if (!\in_array($element['type'], $this->configuration['elements'], true)) {
Expand Down
23 changes: 23 additions & 0 deletions tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -827,4 +827,27 @@ public function provideFix74Cases()
'<?php class Foo { static public ?array $foo; }',
];
}

/**
* @param string $expected
* @param null|string $input
*
* @requires PHP 8.0
* @dataProvider provideFix80Cases
*/
public function testFix80($expected, $input = null)
{
$this->doTest($expected, $input);
}

public function provideFix80Cases()
{
yield [
'<?php class Foo { private int|float|null $foo; }',
];

yield [
'<?php class Foo { private int | /* or empty */ null $foo; }',
];
}
}

0 comments on commit 35997b4

Please sign in to comment.