Просмотр исходного кода

bug #5551 ClassAttributesSeparationFixer - fix for properties with type 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 https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/5550 fix.

Commits
-------

dcf5699e0 ClassAttributesSeparationFixer - fix for properties with type alternation
Dariusz Ruminski 4 лет назад
Родитель
Сommit
cbe98ff805

+ 1 - 1
src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php

@@ -304,7 +304,7 @@ class Sample
      */
     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;
 

+ 21 - 1
tests/Fixer/ClassNotation/ClassAttributesSeparationFixerTest.php

@@ -1416,7 +1416,7 @@ class User3
 }',
         ];
 
-        yield [
+        yield 'constructor property promotion' => [
             '<?php
             class Foo {
                 private array $foo;
@@ -1440,5 +1440,25 @@ class User3
                 ) {}
             }',
         ];
+
+        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;
+            }',
+        ];
     }
 }