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

Merge branch 'master' into 3.0

* master:
  StrictParamFixer - Don't detect functions in use statements
  Do not pull close tag onto same line as a comment
SpacePossum 6 лет назад
Родитель
Сommit
d29633bbdc

+ 9 - 1
src/Fixer/Basic/BracesFixer.php

@@ -342,8 +342,16 @@ class Foo
                 continue;
             }
 
+            $nextNonWhitespaceIndex = $tokens->getNextNonWhitespace($startBraceIndex, " \t");
+            $nextNonWhitespace = $tokens[$nextNonWhitespaceIndex];
+
             /* if CLOSE_TAG is after { on the same line, do not indent. e.g. <?php if ($condition) { ?> */
-            if ($tokens[$tokens->getNextNonWhitespace($startBraceIndex, " \t")]->isGivenKind(T_CLOSE_TAG)) {
+            if ($nextNonWhitespace->isGivenKind(T_CLOSE_TAG)) {
+                continue;
+            }
+
+            /* if CLOSE_TAG is after { on the next line and a comment on this line, do not indent. e.g. <?php if ($condition) { // \n?> */
+            if ($nextNonWhitespace->isComment() && $tokens[$tokens->getNextMeaningfulToken($nextNonWhitespaceIndex)]->isGivenKind(T_CLOSE_TAG)) {
                 continue;
             }
 

+ 2 - 2
src/Fixer/Strict/StrictParamFixer.php

@@ -75,8 +75,8 @@ final class StrictParamFixer extends AbstractFixer
         for ($index = $tokens->count() - 1; 0 <= $index; --$index) {
             $token = $tokens[$index];
 
-            $previousIndex = $tokens->getPrevMeaningfulToken($index);
-            if (null !== $previousIndex && $tokens[$previousIndex]->isGivenKind(CT::T_FUNCTION_IMPORT)) {
+            $nextIndex = $tokens->getNextMeaningfulToken($index);
+            if (null !== $nextIndex && !$tokens[$nextIndex]->equals('(')) {
                 continue;
             }
 

+ 12 - 0
tests/Fixer/Basic/BracesFixerTest.php

@@ -3142,6 +3142,18 @@ function foo()
     }, false);
     ',
             ],
+            [
+                '<?php
+if ($a) { //
+?><?php ++$a;
+} ?>',
+            ],
+            [
+                '<?php
+if ($a) { /* */ /* */ /* */ /* */ /* */
+?><?php ++$a;
+} ?>',
+            ],
         ];
     }
 

+ 10 - 0
tests/Fixer/Strict/StrictParamFixerTest.php

@@ -155,6 +155,16 @@ final class StrictParamFixerTest extends AbstractFixerTestCase
         array_keys($foo, $bar);
     }',
             ],
+            [
+                '<?php
+    use function \base64_decode;
+    foo($bar);',
+            ],
+            [
+                '<?php
+    use function Baz\base64_decode;
+    foo($bar);',
+            ],
         ];
     }