Unverified Commit f79cef4b authored by Chris Burschka's avatar Chris Burschka Committed by GitHub
Browse files

feat(FullyQualifiedNamespace): Disable fixer on conflict between FQN classes...

feat(FullyQualifiedNamespace): Disable fixer on conflict between FQN classes and declared classes (#3137489 by cburschka)
parent e8aa87a5
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -127,6 +127,23 @@ class FullyQualifiedNamespaceSniff implements Sniff
            $useStatement = $phpcsFile->findNext(T_USE, ($endPtr + 1));
        }//end while

        if ($conflict === false) {
            $classStatement = $phpcsFile->findNext(T_CLASS, 0);
            while ($classStatement !== false) {
                $afterClassStatement = $phpcsFile->findNext(T_WHITESPACE, ($classStatement + 1), null, true);
                // Check for 'class ClassName' declarations.
                if ($tokens[$afterClassStatement]['code'] === T_STRING) {
                    $declaredName = $tokens[$afterClassStatement]['content'];
                    if ($declaredName === $className) {
                        $conflict = true;
                        break;
                    }
                }

                $classStatement = $phpcsFile->findNext(T_CLASS, ($classStatement + 1));
            }
        }

        $error = 'Namespaced classes/interfaces/traits should be referenced with use statements';
        if ($conflict === true) {
            $fix = false;
+7 −0
Original line number Diff line number Diff line
@@ -72,4 +72,11 @@ class Example {

  }

  /**
   * Description.
   */
  public function test9(Test\Example $conflictingClass) {

  }

}
+7 −0
Original line number Diff line number Diff line
@@ -73,4 +73,11 @@ class Example {

  }

  /**
   * Description.
   */
  public function test9(Test\Example $conflictingClass) {

  }

}
+1 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ class FullyQualifiedNamespaceUnitTest extends CoderSniffUnitTest
                57 => 1,
                64 => 1,
                71 => 2,
                78 => 1,
            ];
        case 'FullyQualifiedNamespaceUnitTest.1.inc':
            return [16 => 1];