ongr-archive / ongr-strict-standard

[NOT MAINTAINED] Strict PHPCS standard for PSR-2 code based on Squiz standards
MIT License
13 stars 14 forks source link

Checker throws PHP notices on empty function @return comments. #136

Closed kewlar closed 9 years ago

kewlar commented 9 years ago

Let's say we have a @return int in a function's docblock. Here, $token['content'] === 'int '. The result:

PHP Notice: Uninitialized string offset: 0 in .../ongr/ongr-strict-standard/Ongr/Sniffs/Commenting/FunctionCommentSniff.php on line 313

The sniffer correctly reports "Whitespace found at end of line", but it also incorrectly adds "Return comment must start with a capital letter" and "Return comment must end with a full stop". There should not be further errors about a return comment, because there is no return comment.

The bug is both in 2.x and in master branches (line 332 on master branch).

tautrimas commented 9 years ago

Hi (:

Do you have an example with more context?

kewlar commented 9 years ago

Sure thing (:

    /**
     * Get company
     *
     * @return \Pim\UserBundle\Entity\Company 
     */
    public function getCompany()
    {
        return $this->company;
    }

The Doctrine entity code here was probably generated by an IDE or a doctrine:generate:entities command, and it -- stupidly -- left a space symbol at the end of the @return line (not sure if the comment will preserve the whitespace).

The code sniffer throws up on that:

ongr-sniffer-error

If you don't mind, I've got a test, and a fix. Pull request incoming in 3... 2... 1...