Browse Source

Merge branch 'master' into 3.0

Julien Falque 5 years ago
parent
commit
601b764fb1

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

@@ -229,7 +229,7 @@ class Sample
      */
      */
     private function fixSpaceAboveClassElement(Tokens $tokens, $classStartIndex, $elementIndex)
     private function fixSpaceAboveClassElement(Tokens $tokens, $classStartIndex, $elementIndex)
     {
     {
-        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];
+        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];
 
 
         $nonWhiteAbove = null;
         $nonWhiteAbove = null;
 
 

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

@@ -209,7 +209,7 @@ final class Example
     private function getModifiersSequences(Tokens $tokens, $type, $startIndex, $endIndex)
     private function getModifiersSequences(Tokens $tokens, $type, $startIndex, $endIndex)
     {
     {
         if ('property' === $type) {
         if ('property' === $type) {
-            $tokenKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_STATIC, T_VAR, T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE];
+            $tokenKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_STATIC, T_VAR, T_STRING, T_NS_SEPARATOR, CT::T_NULLABLE_TYPE, CT::T_ARRAY_TYPEHINT];
         } else {
         } else {
             $tokenKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_CONST];
             $tokenKinds = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_CONST];
         }
         }

+ 1 - 1
src/Fixer/Phpdoc/PhpdocVarAnnotationCorrectOrderFixer.php

@@ -52,7 +52,7 @@ $foo = 2 + 2;
             }
             }
 
 
             $newContent = Preg::replace(
             $newContent = Preg::replace(
-                '/(@(?:type|var)\s*)(\$\S+)(\s+)([^\$](?:[^<\s]|<[^>]*>)*)(\s|\*)/i',
+                '/(@(?:type|var)\s*)(\$\S+)(\h+)([^\$](?:[^<\s]|<[^>]*>)*)(\s|\*)/i',
                 '$1$4$3$2$5',
                 '$1$4$3$2$5',
                 $token->getContent()
                 $token->getContent()
             );
             );

+ 3 - 1
src/Fixer/StringNotation/ExplicitStringVariableFixer.php

@@ -92,7 +92,9 @@ EOT
             $nextIndex = $index + 1;
             $nextIndex = $index + 1;
             $squareBracketCount = 0;
             $squareBracketCount = 0;
             while (!$this->isStringPartToken($tokens[$nextIndex])) {
             while (!$this->isStringPartToken($tokens[$nextIndex])) {
-                if ($tokens[$nextIndex]->isGivenKind(T_VARIABLE) && 1 !== $squareBracketCount) {
+                if ($tokens[$nextIndex]->isGivenKind(T_CURLY_OPEN)) {
+                    $nextIndex = $tokens->getNextTokenOfKind($nextIndex, [[CT::T_CURLY_CLOSE]]);
+                } elseif ($tokens[$nextIndex]->isGivenKind(T_VARIABLE) && 1 !== $squareBracketCount) {
                     $distinctVariableIndex = $nextIndex;
                     $distinctVariableIndex = $nextIndex;
                     $variableTokens[$distinctVariableIndex] = [
                     $variableTokens[$distinctVariableIndex] = [
                         'tokens' => [$nextIndex => $tokens[$nextIndex]],
                         'tokens' => [$nextIndex => $tokens[$nextIndex]],

+ 2 - 2
src/Tokenizer/TokensAnalyzer.php

@@ -331,7 +331,7 @@ final class TokensAnalyzer
             $prevIndex = $this->tokens->getPrevMeaningfulToken($prevIndex);
             $prevIndex = $this->tokens->getPrevMeaningfulToken($prevIndex);
         }
         }
 
 
-        if ($this->tokens[$prevIndex]->isGivenKind([CT::T_CONST_IMPORT, T_EXTENDS, CT::T_FUNCTION_IMPORT, T_IMPLEMENTS, T_INSTANCEOF, T_INSTEADOF, T_NAMESPACE, T_NEW, CT::T_NULLABLE_TYPE, T_USE, CT::T_USE_TRAIT])) {
+        if ($this->tokens[$prevIndex]->isGivenKind([CT::T_CONST_IMPORT, T_EXTENDS, CT::T_FUNCTION_IMPORT, T_IMPLEMENTS, T_INSTANCEOF, T_INSTEADOF, T_NAMESPACE, T_NEW, CT::T_NULLABLE_TYPE, CT::T_TYPE_COLON, T_USE, CT::T_USE_TRAIT])) {
             return false;
             return false;
         }
         }
 
 
@@ -353,7 +353,7 @@ final class TokensAnalyzer
                 $checkIndex = $this->tokens->getPrevMeaningfulToken($checkIndex);
                 $checkIndex = $this->tokens->getPrevMeaningfulToken($checkIndex);
             }
             }
 
 
-            if ($this->tokens[$checkIndex]->isGivenKind([T_EXTENDS, CT::T_GROUP_IMPORT_BRACE_OPEN, T_IMPLEMENTS, CT::T_USE_TRAIT])) {
+            if ($this->tokens[$checkIndex]->isGivenKind([T_EXTENDS, CT::T_GROUP_IMPORT_BRACE_OPEN, T_IMPLEMENTS, T_USE, CT::T_USE_TRAIT])) {
                 return false;
                 return false;
             }
             }
         }
         }

+ 14 - 0
tests/Fixer/ClassNotation/ClassAttributesSeparationFixerTest.php

@@ -1115,5 +1115,19 @@ private $d = 123;
                 var ? Foo\Bar $qux;
                 var ? Foo\Bar $qux;
             }',
             }',
         ];
         ];
+
+        yield [
+            '<?php
+            class Foo {
+                private array $foo;
+
+                private array $bar;
+            }',
+            '<?php
+            class Foo {
+                private array $foo;
+                private array $bar;
+            }',
+        ];
     }
     }
 }
 }

+ 3 - 0
tests/Fixer/ClassNotation/NoNullPropertyInitializationFixerTest.php

@@ -220,5 +220,8 @@ null;#13
         yield [
         yield [
             '<?php class Foo { protected ? string $bar = null; }',
             '<?php class Foo { protected ? string $bar = null; }',
         ];
         ];
+        yield [
+            '<?php class Foo { protected ? array $bar = null; }',
+        ];
     }
     }
 }
 }

+ 2 - 2
tests/Fixer/ClassNotation/OrderedClassElementsFixerTest.php

@@ -815,13 +815,13 @@ EOT
             '<?php
             '<?php
             class Foo {
             class Foo {
                 public string $bar;
                 public string $bar;
-                public iterable $baz;
+                public array $baz;
                 public ?int $foo;
                 public ?int $foo;
                 public ? Foo\Bar $qux;
                 public ? Foo\Bar $qux;
             }',
             }',
             '<?php
             '<?php
             class Foo {
             class Foo {
-                public iterable $baz;
+                public array $baz;
                 public ? Foo\Bar $qux;
                 public ? Foo\Bar $qux;
                 public string $bar;
                 public string $bar;
                 public ?int $foo;
                 public ?int $foo;

+ 4 - 0
tests/Fixer/ClassNotation/ProtectedToPrivateFixerTest.php

@@ -162,6 +162,10 @@ final class Foo
             '<?php final class Foo { private ?string $foo; }',
             '<?php final class Foo { private ?string $foo; }',
             '<?php final class Foo { protected ?string $foo; }',
             '<?php final class Foo { protected ?string $foo; }',
         ];
         ];
+        yield [
+            '<?php final class Foo { private array $foo; }',
+            '<?php final class Foo { protected array $foo; }',
+        ];
     }
     }
 
 
     private function getAttributesAndMethods($original)
     private function getAttributesAndMethods($original)

+ 9 - 0
tests/Fixer/ClassNotation/SingleClassElementPerStatementFixerTest.php

@@ -851,5 +851,14 @@ EOT
                 var ? Foo\Bar $foo, $bar;
                 var ? Foo\Bar $foo, $bar;
             }',
             }',
         ];
         ];
+        yield [
+            '<?php class Foo {
+                var array $foo;
+                var array $bar;
+            }',
+            '<?php class Foo {
+                var array $foo, $bar;
+            }',
+        ];
     }
     }
 }
 }

Some files were not shown because too many files changed in this diff