Skip to content

Commit

Permalink
bug #5551 ClassAttributesSeparationFixer - fix for properties with ty…
Browse files Browse the repository at this point in the history
…pe alternation (kubawerlos, keradus)

This PR was squashed before being merged into the 2.18 branch.

Discussion
----------

ClassAttributesSeparationFixer - fix for properties with type alternation

Commented part in test can be commented out after #5550 fix.

Commits
-------

dcf5699 ClassAttributesSeparationFixer - fix for properties with type alternation
  • Loading branch information
keradus committed Mar 17, 2021
2 parents a1467ec + dcf5699 commit cbe98ff
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ private function fixSpaceBelowClassMethod(Tokens $tokens, $classEndIndex, $eleme
*/
private function fixSpaceAboveClassElement(Tokens $tokens, $classStartIndex, $elementIndex, $spacing)
{
static $methodAttr = [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_ABSTRACT, T_FINAL, T_STATIC, T_STRING, T_NS_SEPARATOR, T_VAR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT];
static $methodAttr = [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_ABSTRACT, T_FINAL, T_STATIC, T_STRING, T_NS_SEPARATOR, T_VAR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT, CT::T_TYPE_ALTERNATION];

$nonWhiteAbove = null;

Expand Down
22 changes: 21 additions & 1 deletion tests/Fixer/ClassNotation/ClassAttributesSeparationFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@ class User3
}',
];

yield [
yield 'constructor property promotion' => [
'<?php
class Foo {
private array $foo;
Expand All @@ -1440,5 +1440,25 @@ public function __construct(
) {}
}',
];

yield 'typed properties' => [
'<?php
class Foo {
private static int | float | null $a;
private static int | float | null $b;
private int | float | null $c;
private int | float | null $d;
}',
'<?php
class Foo {
private static int | float | null $a;
private static int | float | null $b;
private int | float | null $c;
private int | float | null $d;
}',
];
}
}

0 comments on commit cbe98ff

Please sign in to comment.