Unverified Commit f3ddc650 authored by Mitch Portier's avatar Mitch Portier Committed by GitHub
Browse files

fix(FullyQualifiedNamespace): Add support for multi-use statements (#3118337 by Arkener)

parent b9c7833a
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -66,9 +66,11 @@ class FullyQualifiedNamespaceSniff implements Sniff
        }

        // Check if this is a use statement and ignore those.
        $before = $phpcsFile->findPrevious([T_STRING, T_NS_SEPARATOR, T_WHITESPACE], $stackPtr, null, true);
        $before = $phpcsFile->findPrevious([T_STRING, T_NS_SEPARATOR, T_WHITESPACE, T_COMMA, T_AS], $stackPtr, null, true);
        if ($tokens[$before]['code'] === T_USE || $tokens[$before]['code'] === T_NAMESPACE) {
            return $phpcsFile->findNext([T_STRING, T_NS_SEPARATOR], ($stackPtr + 1), null, true);
            return $phpcsFile->findNext([T_STRING, T_NS_SEPARATOR, T_WHITESPACE, T_COMMA, T_AS], ($stackPtr + 1), null, true);
        } else {
            $before = $phpcsFile->findPrevious([T_STRING, T_NS_SEPARATOR, T_WHITESPACE], $stackPtr, null, true);
        }

        // If this is a namespaced function call then ignore this because use
@@ -116,6 +118,12 @@ class FullyQualifiedNamespaceSniff implements Sniff
            }

            $aliasName = false;
            // Check if we're currently in a multi-use statement.
            if ($tokens[$endPtr]['code'] === T_COMMA) {
                $useStatement = $endPtr;
                continue;
            }

            $useStatement = $phpcsFile->findNext(T_USE, ($endPtr + 1));
        }//end while

+9 −0
Original line number Diff line number Diff line
@@ -8,6 +8,8 @@
use Test\Bar;
use Test\NotUsed;
use Test\Alias as TestAlias;
use Test\MultiLine as MultiLineAlias,
    Test\MultiLineSecond;

/**
 * Example.
@@ -63,4 +65,11 @@ class Example {

  }

  /**
   * Description.
   */
  public function test8(Test\MultiLine $multiLine, Test\MultiLineSecond $multiLineSecond) {

  }

}
+9 −0
Original line number Diff line number Diff line
@@ -5,10 +5,12 @@
 * Example.
 */

use Test\MultiLineSecond;
use Test\Foo;
use Test\NotUsed;
use Test\Bar;
use Test\Alias as TestAlias;
use Test\MultiLine as MultiLineAlias;

/**
 * Example.
@@ -64,4 +66,11 @@ class Example {

  }

  /**
   * Description.
   */
  public function test8(MultiLineAlias $multiLine, MultiLineSecond $multiLineSecond) {

  }

}
+6 −5
Original line number Diff line number Diff line
@@ -23,11 +23,12 @@ class FullyQualifiedNamespaceUnitTest extends CoderSniffUnitTest
        switch ($testFile) {
        case 'FullyQualifiedNamespaceUnitTest.inc':
            return [
                27 => 1,
                34 => 1,
                41 => 1,
                55 => 1,
                62 => 1,
                29 => 1,
                36 => 1,
                43 => 1,
                57 => 1,
                64 => 1,
                71 => 2,
            ];
        case 'FullyQualifiedNamespaceUnitTest.1.inc':
            return [16 => 1];