Browse Source

BracesFixer - handle dynamic static method call

SpacePossum 5 years ago
parent
commit
239938deae
2 changed files with 16 additions and 1 deletions
  1. 1 1
      src/Fixer/Basic/BracesFixer.php
  2. 15 0
      tests/Fixer/Basic/BracesFixerTest.php

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

@@ -424,7 +424,7 @@ class Foo
                         // and it is not a `Foo::{bar}()` situation
                         !($nestToken->equals('}') && $nextNonWhitespaceNestToken->equals('(')) &&
                         // and it is not a `${"a"}->...` and `${"b{$foo}"}->...` situation
-                        !($nestToken->equals('}') && $tokens[$nestIndex - 1]->equalsAny(['"', "'", [T_CONSTANT_ENCAPSED_STRING]])) &&
+                        !($nestToken->equals('}') && $tokens[$nestIndex - 1]->equalsAny(['"', "'", [T_CONSTANT_ENCAPSED_STRING], [T_VARIABLE]])) &&
                         // and next token is not a closing tag that would break heredoc/nowdoc syntax
                         !($tokens[$nestIndex - 1]->isGivenKind(T_END_HEREDOC) && $nextNonWhitespaceNestToken->isGivenKind(T_CLOSE_TAG))
                     ) {

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

@@ -5248,4 +5248,19 @@ function foo()
             ],
         ];
     }
+
+    public function testDynamicStaticMethodCallNotTouched()
+    {
+        $this->doTest(
+            '<?php
+SomeClass::{$method}(new \stdClass());
+SomeClass::{\'test\'}(new \stdClass());
+
+function example()
+{
+    SomeClass::{$method}(new \stdClass());
+    SomeClass::{\'test\'}(new \stdClass());
+}'
+        );
+    }
 }