Symfony-coding-standard icon indicating copy to clipboard operation
Symfony-coding-standard copied to clipboard

The ruleset force to add PHPDoc blocks for all methods

Open Kwadz opened this issue 7 years ago • 12 comments

The Symfony coding strandard documentation states:

Add PHPDoc blocks for all classes, methods, and functions (though you may be asked to remove PHPDoc that do not add value);

For example the inherited methods should not contain any PHPDoc comments, except if we want to add additional details.

Kwadz avatar Jan 08 '18 14:01 Kwadz

I agree. Furthermore, the rules should also sniff useless PHPdoc @param and @return lines like this:

class Test {
    /**
     * @param string $a
     * @param int $b with description.
     *
     * @return int
     */
    public function test(string $a, int $b): int
    {
        return 42;
    }
}

Only $b param notation should be kept because of the custom description.

soullivaneuh avatar Jan 24 '18 10:01 soullivaneuh

Maybe including this rule will be enough: https://github.com/slevomat/coding-standard#slevomatcodingstandardtypehintstypehintdeclaration-

soullivaneuh avatar Jan 24 '18 10:01 soullivaneuh

PHPdoc @param and @return statements without description are not totally useless. It helps in cases without type declaration (PHP 7). Then I would keep the description as optional. What do you think?

Kwadz avatar Jan 30 '18 05:01 Kwadz

It helps in cases without type declaration (PHP 7)

The rule I suggested removes the phpdoc only if useless. It wont touch anything if the PHP 7 typing is not used.

soullivaneuh avatar Feb 17 '18 11:02 soullivaneuh

Hey! No plan for this rules ?

Xen3r0 avatar Jun 14 '19 06:06 Xen3r0

PHP-CS-Fixer released a new version which configure the Symfony rule for removing PHPDocs when not necessary. At the moment we can't use both PHP-CS-Fixer and this project because the first one remove PHPDocs and the second is requiring them.

tifabien avatar Dec 02 '19 11:12 tifabien

you can add the following to your php-cs-fixer config

 'no_superfluous_phpdoc_tags' => false,

symfony coding standard still states:

Add PHPDoc blocks for all classes, methods, and functions (though you may be asked to remove PHPDoc that do not add value);

https://symfony.com/doc/current/contributing/code/standards.html#documentation

wickedOne avatar Dec 02 '19 16:12 wickedOne

additionally you should be able to add the following snippet to your phpcs.xml

<rule ref="Symfony.Commenting.FunctionComment.MissingParamTag">
    <severity>0</severity>
</rule>

wickedOne avatar Dec 02 '19 16:12 wickedOne

ah ic, you want the parameter requirement to be dropped raqther than the docblock requirement. would make sense with php 7.4+ and property typing i guess...

wickedOne avatar Dec 02 '19 20:12 wickedOne

What I would like is to use the php-cs-fixer @Symfony rule (with the 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true, 'allow_unused_params' => true] config). This way superfluous PHPDocs can be removed because they are redundant with typehinted parameters. I assume that if I add the MissingParamTag config phpcs won't report error if an parameter is not typehinted and no @param is added in PHPDoc isn't it? IMHO it make sense to remove redundant PHPDocs as it will lighten the code.

tifabien avatar Dec 03 '19 09:12 tifabien

though i understand your sentiment, my problem with this is that it's not part of the coding standard / explicitly stated.

so i'd vote for removal of the paramter annotation as that's not explicitly stated as well, and just require a docblock regardless of it's contents, but would say that any additional / custom requirements for parameter annotations should be part of your private sniffs / config.

@djoos what are your thoughts on this?

wickedOne avatar Dec 08 '19 22:12 wickedOne

Please see https://github.com/djoos/Symfony-coding-standard/pull/183 for a start to use Slevomat sniffs instead of homegrown ones and comment there. Pulling in more sniffs would be super easy then.

mmoll avatar Nov 07 '20 18:11 mmoll