Allow methods without docComment if comment does not provide additional value

Discussion Topic

Current CGL states that every method has to have a docComment / phpDoc - even methods without parameters or return types - for example constructors, resulting in comments like “constructor”. I’d like to propose to make the description part of the docComment (and thus the whole comment if no params/return type) optional to also get rid of simple getter/setter comments (what’s the benefit of the “get the ID” comment on top of a getId() method?).


  • CGL Adjustment to allow methods without comment


  • Less “noise”
  • Higher percentage of comments you should actually read


  • Less strict rules, developers need to think about comment necessity (and content) more

Remarks and notes


Topic Initiator: Susi Moog
Topic Mentor: Susi Moog



same goes for class comments (when only “Class Package/ClassName” is stated), which could be removed as well - also for object properties:

One info worth mentioning is the proposal of PHP-FIG:

That php-doc-standard also just “recommends” using a DocBlock. That would allow us to interpret it as Susi suggests. I agree over-simple doc-blocks don’t help at all. Our PSR-standards also don’t forbid us to skip docblocks? (We wanted to stick to established standards, even if they might be unpopular).

Imho if we make it optional we will still be able to point out during code-reviews for which cases we definitely would want a docblock. We also currently check if the docblock makes sense or needs to be more precise/extensive/… So that should work out.

PSR-2 states:
“There are many elements of style and practice intentionally omitted by this guide. These include but are not limited to:
… Comments …”

I really appreciate the idea of leaving out unnecessary comments out. Right now, we often have the situation of comments for the sake of comments. They blow up the code and have no additional value.
However, I see the danger of lazy developers using that weaker rule as an excuse to stop commenting. But as Stefan says that could be caught at the code review.

Following Susi`s suggestion we would move close to one of the best practice rules of TheCodingMachine:

I fully support the proposal.

Absolutely yes. It’s what we do (deliberately violating the TYPO3 CGL) in our projects already. Especially when you use the PHP7 style native type hinting for parameters and return types the phpDoc in many cases is completely useless.

1 Like

Yes please, but we really have to check in code reviews on missing docComments that do have value.

1 Like

This topic was automatically closed after 28 days. New replies are no longer allowed.