Closed SebastianS90 closed 6 years ago
@SebastianS90 Please post full example. Your code should not be checked because there is no doccomment.
phpcs.xml
<?xml version="1.0"?>
<ruleset name="Custom Standard">
<config name="installed_paths" value="../../slevomat/coding-standard"/>
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
<properties>
<property name="searchAnnotations" value="1"/>
</properties>
</rule>
</ruleset>
foo.php
<?php
/**
* Just a small test.
*
* @throws \Exception
*/
function foo(): void
{
throw new Exception();
}
$ phpcs foo.php
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
6 | ERROR | [x] Class \Exception 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.
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
$ phpcbf foo.php
PHPCBF RESULT SUMMARY
-----------------------------------------------------------------------
FILE FIXED REMAINING
-----------------------------------------------------------------------
foo.php 1 0
-----------------------------------------------------------------------
A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE
-----------------------------------------------------------------------
foo.php
<?php
/**
* Just a small test.
*
* throws \Exception
*/
function foo(): void
{
throw new Exception();
}
$ git diff
diff --git a/foo.php b/foo.php
--- a/foo.php
+++ b/foo.php
@@ -3,7 +3,7 @@
/**
* Just a small test.
*
- * @throws \Exception
+ * throws \Exception
*/
function foo(): void
{
Thank you for your report. Fixed in https://github.com/slevomat/coding-standard/commit/2b5a5a2768f058fd77cb069974b7fe9427cae94c
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFullyQualifiedNameWithoutNamespace
The fix does:
But it should: