Browse Source

Merge branch '2.19' into 3.0

# Conflicts:
#	src/Tokenizer/TokensAnalyzer.php
Dariusz Ruminski 3 years ago
parent
commit
637d3439c5

+ 0 - 1
src/Tokenizer/TokensAnalyzer.php

@@ -555,7 +555,6 @@ final class TokensAnalyzer
                 T_SR => true,                   // >>
                 T_SR_EQUAL => true,             // >>=
                 T_XOR_EQUAL => true,            // ^=
-                CT::T_TYPE_ALTERNATION => true, // |
                 T_SPACESHIP => true,            // <=>
                 T_COALESCE => true,             // ??
             ];

+ 18 - 2
tests/Fixer/Operator/BinaryOperatorSpacesFixerTest.php

@@ -1993,12 +1993,11 @@ $a = $ae?? $b;
                 ['operators' => ['=>' => BinaryOperatorSpacesFixer::ALIGN_SINGLE_SPACE_MINIMAL]],
             ],
             'multiple exceptions catch, default config' => [
-                '<?php try {} catch (A | B $e) {}',
                 '<?php try {} catch (A   |     B $e) {}',
             ],
             'multiple exceptions catch, no space config' => [
-                '<?php try {} catch (A|B $e) {}',
                 '<?php try {} catch (A   |     B $e) {}',
+                null,
                 ['operators' => ['|' => BinaryOperatorSpacesFixer::NO_SPACE]],
             ],
         ];
@@ -2039,4 +2038,21 @@ $a = $ae?? $b;
             ],
         ];
     }
+
+    /**
+     * @requires PHP 8.0
+     */
+    public function testUnionTypesAreNotChanged(): void
+    {
+        $this->doTest(
+            '<?php
+            class Foo
+            {
+                private bool|int | string $prop;
+                public function bar(TypeA | TypeB|TypeC $x): TypeA|TypeB | TypeC|TypeD
+                {
+                }
+            }'
+        );
+    }
 }

+ 4 - 4
tests/Fixtures/Integration/misc/PHP8_0.test

@@ -57,14 +57,14 @@ $object = new #[ExampleAttribute] class()
 // https://wiki.php.net/rfc/union_types_v2
 class Number
 {
-    private int | float | null $number;
+    private int|float|null $number;
 
     public function setNumber(int | float $number): void
     {
         $this->number = $number;
     }
 
-    public function getNumber(): int | float | null
+    public function getNumber(): int|float | null
     {
         return $this->number;
     }
@@ -234,12 +234,12 @@ class Number
 {
     private int|float|null $number;
 
-    public function setNumber(int|float $number): void
+    public function setNumber(int | float $number): void
     {
         $this->number = $number;
     }
 
-    public function getNumber(): int|float|null
+    public function getNumber(): int|float | null
     {
         return $this->number;
     }

+ 1 - 1
tests/Tokenizer/TokensAnalyzerTest.php

@@ -1507,7 +1507,7 @@ $b;',
         return [
             [
                 '<?php try {} catch (A | B $e) {}',
-                [11 => true],
+                [11 => false],
             ],
         ];
     }