diff --git a/SlevomatCodingStandard/Helpers/ReferencedNameHelper.php b/SlevomatCodingStandard/Helpers/ReferencedNameHelper.php index 5bb8b0293..9c2cde617 100644 --- a/SlevomatCodingStandard/Helpers/ReferencedNameHelper.php +++ b/SlevomatCodingStandard/Helpers/ReferencedNameHelper.php @@ -161,6 +161,7 @@ private static function isReferencedName(PHP_CodeSniffer_File $phpcsFile, $start T_DOUBLE_COLON, T_OBJECT_OPERATOR, T_NAMESPACE, + T_CONST, ]; if ($previousToken['code'] === T_USE) { diff --git a/tests/Helpers/ReferencedNameHelperTest.php b/tests/Helpers/ReferencedNameHelperTest.php index 7f4d48d35..45e965d3c 100644 --- a/tests/Helpers/ReferencedNameHelperTest.php +++ b/tests/Helpers/ReferencedNameHelperTest.php @@ -99,4 +99,13 @@ public function testReturnTypehint() $this->assertSame('\OtherNamespace\Lorem', $names[1]->getNameAsReferencedInFile()); } + public function testConstantIsNotReferencedName() + { + $codeSnifferFile = $this->getCodeSnifferFile( + __DIR__ . '/data/class-constant.php' + ); + $names = ReferencedNameHelper::getAllReferencedNames($codeSnifferFile, 0); + $this->assertCount(0, $names); + } + } diff --git a/tests/Helpers/data/class-constant.php b/tests/Helpers/data/class-constant.php new file mode 100644 index 000000000..94525d434 --- /dev/null +++ b/tests/Helpers/data/class-constant.php @@ -0,0 +1,8 @@ +assertNoSniffError($report, 5); } + public function testMatchingCaseOfUseAndClassConstant() + { + $report = $this->checkFile(__DIR__ . '/data/matchingCaseOfUseAndClassConstant.php'); + $this->assertNoSniffErrorInFile($report); + } + } diff --git a/tests/Sniffs/Namespaces/data/matchingCaseOfUseAndClassConstant.php b/tests/Sniffs/Namespaces/data/matchingCaseOfUseAndClassConstant.php new file mode 100644 index 000000000..e58e86070 --- /dev/null +++ b/tests/Sniffs/Namespaces/data/matchingCaseOfUseAndClassConstant.php @@ -0,0 +1,18 @@ +getAbsoluteUrl(); + } + +}