Loading coder_sniffer/Drupal/Sniffs/Classes/UnusedUseStatementSniff.php +16 −1 Original line number Diff line number Diff line Loading @@ -130,7 +130,22 @@ class UnusedUseStatementSniff implements Sniff ); // If a backslash is used before the class name then this is some other // use statement. if ($tokens[$beforeUsage]['code'] !== T_USE && $tokens[$beforeUsage]['code'] !== T_NS_SEPARATOR) { if (in_array( $tokens[$beforeUsage]['code'], [ T_USE, T_NS_SEPARATOR, // If an object operator is used then this is a method call // with the same name as the class name. Which means this is // not referring to the class. T_OBJECT_OPERATOR, // Function definition, not class invocation. T_FUNCTION, // Static method call, not class invocation. T_DOUBLE_COLON, ] ) === false ) { return; } Loading coder_sniffer/Drupal/Test/Classes/UnusedUseStatementUnitTest.inc +24 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,9 @@ use /* I like weird comment placements */ MyNamespace\Depth\AnotherUnusedSameNam use MyNamespace\Depth\SomeClass as CoreSomeClass; use Some\Data\VarName; use Some\Data\VarName2 as AliasVarName2; use Some\Data\SameAsAMethodName; use Some\Data\Test9; use Some\Data\Test10; /** * Bla. Loading Loading @@ -99,4 +102,25 @@ class Pum { return $x['test']; } /** * Call a method here that has the same name as a class name. */ protected function test8() { $this->sameAsAMethodName(); } /** * Method definition has same name as class name. */ protected function test9() { } /** * Static method calls should not be confused with class names. */ protected function test10() { Something::test10(); } } coder_sniffer/Drupal/Test/Classes/UnusedUseStatementUnitTest.inc.fixed +21 −0 Original line number Diff line number Diff line Loading @@ -89,4 +89,25 @@ class Pum { return $x['test']; } /** * Call a method here that has the same name as a class name. */ protected function test8() { $this->sameAsAMethodName(); } /** * Method definition has same name as class name. */ protected function test9() { } /** * Static method calls should not be confused with class names. */ protected function test10() { Something::test10(); } } coder_sniffer/Drupal/Test/Classes/UnusedUseStatementUnitTest.php +3 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,9 @@ class UnusedUseStatementUnitTest extends CoderSniffUnitTest 17 => 1, 19 => 1, 20 => 1, 21 => 1, 22 => 1, 23 => 1, ); }//end getWarningList() Loading Loading
coder_sniffer/Drupal/Sniffs/Classes/UnusedUseStatementSniff.php +16 −1 Original line number Diff line number Diff line Loading @@ -130,7 +130,22 @@ class UnusedUseStatementSniff implements Sniff ); // If a backslash is used before the class name then this is some other // use statement. if ($tokens[$beforeUsage]['code'] !== T_USE && $tokens[$beforeUsage]['code'] !== T_NS_SEPARATOR) { if (in_array( $tokens[$beforeUsage]['code'], [ T_USE, T_NS_SEPARATOR, // If an object operator is used then this is a method call // with the same name as the class name. Which means this is // not referring to the class. T_OBJECT_OPERATOR, // Function definition, not class invocation. T_FUNCTION, // Static method call, not class invocation. T_DOUBLE_COLON, ] ) === false ) { return; } Loading
coder_sniffer/Drupal/Test/Classes/UnusedUseStatementUnitTest.inc +24 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,9 @@ use /* I like weird comment placements */ MyNamespace\Depth\AnotherUnusedSameNam use MyNamespace\Depth\SomeClass as CoreSomeClass; use Some\Data\VarName; use Some\Data\VarName2 as AliasVarName2; use Some\Data\SameAsAMethodName; use Some\Data\Test9; use Some\Data\Test10; /** * Bla. Loading Loading @@ -99,4 +102,25 @@ class Pum { return $x['test']; } /** * Call a method here that has the same name as a class name. */ protected function test8() { $this->sameAsAMethodName(); } /** * Method definition has same name as class name. */ protected function test9() { } /** * Static method calls should not be confused with class names. */ protected function test10() { Something::test10(); } }
coder_sniffer/Drupal/Test/Classes/UnusedUseStatementUnitTest.inc.fixed +21 −0 Original line number Diff line number Diff line Loading @@ -89,4 +89,25 @@ class Pum { return $x['test']; } /** * Call a method here that has the same name as a class name. */ protected function test8() { $this->sameAsAMethodName(); } /** * Method definition has same name as class name. */ protected function test9() { } /** * Static method calls should not be confused with class names. */ protected function test10() { Something::test10(); } }
coder_sniffer/Drupal/Test/Classes/UnusedUseStatementUnitTest.php +3 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,9 @@ class UnusedUseStatementUnitTest extends CoderSniffUnitTest 17 => 1, 19 => 1, 20 => 1, 21 => 1, 22 => 1, 23 => 1, ); }//end getWarningList() Loading