DEV Community

Discussion on: Code comments are (mostly) a violation of DRY

Collapse
 
matthewbdaly profile image
Matthew Daly • Edited

In PHP I find Psalm incredibly useful for stuff like this. It will flag any discrepancies in your DocBlocks and can often fix them automatically. It also supports using DocBlocks to specify some quite complex type information, such as arrays with a specific structure.

Obviously type hints are the best way to specify this sort of thing since they're enforced by the compiler, but they can't always be as specific as DocBlocks can - you can enforce a return type being an array with a type hint, but you can't enforce the structure of said array.

Collapse
 
danrot90 profile image
Daniel Rotter

Agree, and if the comment includes information like that, it is not a pure duplication of what the code already says. Different story though if PHP supports generics at some point.