Code formatting guideline

Hi,

is there any guide for code formatting rules for Yii3?

For instance inserting variables somewhere in the middle of the code is a bad practice like here - one has to read through file in order to find the variable & definition. Variables should be all at the top.

Also I would suggest to put comments to all public methods.

Another question would be whether it would be possible to use protected properties instead of private to allow flexibility for inheritance. Many PRs in the past have changed private scope to protected.

It’s generally PSR-12. We can add more rules on top (there’s no such document yet). Your “variables at the top” rule makes sense.

Putting comment to a public method doesn’t make sense if it adds nothing to what’s obvious from
method name, argument names and types. Also it doesn’t make sense to put @inheritdoc everywhere. It is default IDE behavior.

We design code to be extensible via composition so that’s not what we want in majority of cases. Thus, default is private unless justified.

2 Likes
1 Like