diff --git a/SlevomatCodingStandard/Sniffs/Namespaces/ReferenceUsedNamesOnlySniff.php b/SlevomatCodingStandard/Sniffs/Namespaces/ReferenceUsedNamesOnlySniff.php index 4dfa9f532..7b0637286 100644 --- a/SlevomatCodingStandard/Sniffs/Namespaces/ReferenceUsedNamesOnlySniff.php +++ b/SlevomatCodingStandard/Sniffs/Namespaces/ReferenceUsedNamesOnlySniff.php @@ -127,8 +127,6 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $openTagPointer) if ( !NamespaceHelper::hasNamespace($name) && NamespaceHelper::findCurrentNamespaceName($phpcsFile, $pointer) === null - && !in_array($name, ['\Exception', '\Throwable'], true) - && (!StringHelper::endsWith($name, 'Error') || NamespaceHelper::hasNamespace($name)) ) { $phpcsFile->addError(sprintf( 'Type %s should not be referenced via a fully qualified name, but via an unqualified name without the leading \\, because the file does not have a namespace and the type cannot be put in a use statement', diff --git a/tests/Sniffs/Namespaces/ReferenceUsedNamesOnlySniffTest.php b/tests/Sniffs/Namespaces/ReferenceUsedNamesOnlySniffTest.php index 3e0f6a26b..e8c178cf8 100644 --- a/tests/Sniffs/Namespaces/ReferenceUsedNamesOnlySniffTest.php +++ b/tests/Sniffs/Namespaces/ReferenceUsedNamesOnlySniffTest.php @@ -147,19 +147,19 @@ public function testDoNotAllowFullyQualifiedExceptionsInCatch() $this->assertSniffError( $report, 22, - ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME, + ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME_WITHOUT_NAMESPACE, '\Throwable' ); $this->assertSniffError( $report, 24, - ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME, + ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME_WITHOUT_NAMESPACE, '\Exception' ); $this->assertSniffError( $report, 26, - ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME, + ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME_WITHOUT_NAMESPACE, '\TypeError' ); $this->assertSniffError(