taken from Your code sucks, let's fix it - By Rafael Dohms
Be aware of whether your code is:
Object Calisthenics + Readability Tips
Only one indentation level per method
“Wait, I can't even have two nested foreach blocks?”
Nope. Return early, and consider whether your algorithm could be simplified by using PHP's built-in functions. If not, just break it up into reusable pieces. Separation of concerns.
Don't use 'else'
This plays into #1. Helps avoid code duplication and makes it easier to understand since there's only one decision path.
Wrap primitive types if you need to attach behavior
For example, if a function takes a parameter that doesn't satisfy readability in the calling code, maybe it needs to be wrapped in something else, like an object.
Only one '→' per line, unless getters or fluent
Properties are harder to mock for testing than methods.
With fluency, align arrows and don't do too many levels without making sure they all return proper things to avoid exceptions.
Also consider how auto-completable your functions are.
Don't abbreviate variable and function names
And don't try to pack too much information in either, as this is a symptom of bad encapsulation or something. Use meaningful function names.
Keep your classes small
No more than 100-200 lines per class, maybe 20 lines per method
Limit the number of instance variables in classes to 5
Use first-class collections
Do use getters/setters
because they allow you to inject stuff like lazy loading,
Document your code!