Skip to content
Snippets Groups Projects
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
Branches
Tags
No related merge requests found
......@@ -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;
......
......@@ -72,4 +72,11 @@ class Example {
}
/**
* Description.
*/
public function test9(Test\Example $conflictingClass) {
}
}
......@@ -73,4 +73,11 @@ class Example {
}
/**
* Description.
*/
public function test9(Test\Example $conflictingClass) {
}
}
......@@ -29,6 +29,7 @@ class FullyQualifiedNamespaceUnitTest extends CoderSniffUnitTest
57 => 1,
64 => 1,
71 => 2,
78 => 1,
];
case 'FullyQualifiedNamespaceUnitTest.1.inc':
return [16 => 1];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment