slevomat / coding-standard

Slevomat Coding Standard for PHP_CodeSniffer provides many useful sniffs
MIT License
1.39k stars 171 forks source link

FQN is not reported in property annotation #258

Closed morozov closed 6 years ago

morozov commented 6 years ago

Example script:

<?php

namespace Acme;

class Foo
{
    /**
     * @var \Doctrine\DBAL\Connection
     */
    public $conn;
}

$conn = new \Doctrine\DBAL\Connection();

Actual output:

------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------
 13 | ERROR | [x] Class \Doctrine\DBAL\Connection should not be referenced via a fully
    |       |     qualified name, but via a use statement.
------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------

Expected output: line 8 should be reported as containing FQN as well.

Please see https://github.com/doctrine/dbal/pull/3002#discussion_r165686652 for the reference.

kukulich commented 6 years ago

Hmm, the sniff does not check any doccomment but it should be possible very easy. I hope :)

kukulich commented 6 years ago

@morozov Could you please try https://github.com/slevomat/coding-standard/commit/c73280903ece590687d0d9abdddb8e8efdb017ca ?

morozov commented 6 years ago

Thanks @kukulich. I checked out the commit above and enabled searchAnnotations for SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly in our ruleset.xml. Still same output.

Most likely, I'm just doing something wrong. @Majkl578 could you please check this?

Majkl578 commented 6 years ago

Testing on ORM, seems to work, or at least report errors like:

FILE: lib/Doctrine/ORM/Query/Exec/AbstractSqlExecutor.php
--------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------------------------
 56 | ERROR | [x] Class \Doctrine\DBAL\Driver\Statement should not be referenced via a fully qualified name, but via a use statement.

For @return here.

To enable, require slevomat/coding-standard: dev-master as 4.3.99 and just add:

            <property name="searchAnnotations" type="boolean" value="true"/>

and delete cache file .phpcs-cache.

morozov commented 6 years ago

Clearing cache worked for me:

------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
------------------------------------------------------------------------------------------------
  8 | ERROR | [x] Class \Doctrine\DBAL\Connection should not be referenced via a fully
    |       |     qualified name, but via a use statement.
 13 | ERROR | [x] Class \Doctrine\DBAL\Connection should not be referenced via a fully
    |       |     qualified name, but via a use statement.
------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------

Thank you @Majkl578.

github-actions[bot] commented 4 years ago

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.