Add rule to sort class methods by their modifiers and usage in other methods
There are already rules that enforce following order:
- attributes
- getters/setters
- constructor
- methods
I propose to make it stricter and enforce order of methods:
- attributes
- public getters/setters
- private getters/setters?
- constructor
- overrides
- public methods*
- private methods*
* - can go above in order if they go just after method they are used in
BAD:
_privateMethod() {
...
}
publicMethod() {
...
}
@override
overwritenMethod() {
...
}
GOOD:
@override
overwritenMethod() {
...
}
publicMethod() {
...
}
_privateMethod() {
...
}
GOOD:
@override
overwritenMethod() {
...
_privateMethod();
...
}
_privateMethod() {
...
}
publicMethod() {
...
}
That would require a custom rule, correct?
There is an updated dcm functionality that I believe allows doing this
It probably doesn't cover this case:
- can go above in order if they go just after method they are used in
It probably doesn't cover this case:
can go above in order if they go just after method they are used in
Yes, it doesn't seem to, but it allows to enforce privates/overrides, but I guess it's too strict without allowing the mixed order depending on usage?
That would require a custom rule, correct?
More like a variant of existing one, but yes