Skip to content

Commit f4c1d43

Browse files
committed
ReferenceUsedNamesOnlySniff - \Exception, \Throwable and PHP Errors in files without namespace are supposed to be unqualified
1 parent 9245fbe commit f4c1d43

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

SlevomatCodingStandard/Sniffs/Namespaces/ReferenceUsedNamesOnlySniff.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $openTagPointer)
127127
if (
128128
!NamespaceHelper::hasNamespace($name)
129129
&& NamespaceHelper::findCurrentNamespaceName($phpcsFile, $pointer) === null
130-
&& !in_array($name, ['\Exception', '\Throwable'], true)
131-
&& (!StringHelper::endsWith($name, 'Error') || NamespaceHelper::hasNamespace($name))
132130
) {
133131
$phpcsFile->addError(sprintf(
134132
'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',

tests/Sniffs/Namespaces/ReferenceUsedNamesOnlySniffTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,19 @@ public function testDoNotAllowFullyQualifiedExceptionsInCatch()
147147
$this->assertSniffError(
148148
$report,
149149
22,
150-
ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME,
150+
ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME_WITHOUT_NAMESPACE,
151151
'\Throwable'
152152
);
153153
$this->assertSniffError(
154154
$report,
155155
24,
156-
ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME,
156+
ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME_WITHOUT_NAMESPACE,
157157
'\Exception'
158158
);
159159
$this->assertSniffError(
160160
$report,
161161
26,
162-
ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME,
162+
ReferenceUsedNamesOnlySniff::CODE_REFERENCE_VIA_FULLY_QUALIFIED_NAME_WITHOUT_NAMESPACE,
163163
'\TypeError'
164164
);
165165
$this->assertSniffError(

0 commit comments

Comments
 (0)