Skip to content

Commit

Permalink
ReferenceUsedNamesOnlySniff - \Exception, \Throwable and PHP Errors i…
Browse files Browse the repository at this point in the history
…n files without namespace are supposed to be unqualified
  • Loading branch information
ondrejmirtes committed Aug 10, 2016
1 parent 9245fbe commit f4c1d43
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
6 changes: 3 additions & 3 deletions tests/Sniffs/Namespaces/ReferenceUsedNamesOnlySniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit f4c1d43

Please sign in to comment.