Jeff Bay in 2008 • Adapted for PHP by Rafael Dohms and Guilherme Blanco in 2012 • "Your code sucks, let's fix it” • https://www.slideshare.net/rdohms/bettercode- phpbenelux212alternate • Laracasts series "Simple Rules for Simpler Code" • https://laracasts.com/series/simple-rules-for-simpler-code
Do not use “else” keyword Wrap primitive types and strings First class collections Only one object operator per line Don’t abbreviate Keep classes small No classes with more than two instance variables No getter/setters
Do not use “else” keyword Wrap primitive types and strings First class collections Only one object operator per line Don’t abbreviate Keep classes small No classes with more than two instance variables No getter/setters
late 90s and then later by Martin Fowler in "Refactoring" • https://martinfowler.com/books/refactoring.html • Sandi Metz - Get a whiff of this • https://speakerdeck.com/skmetz/get-a-whiff-of- this
List Divergent Change Shotgun Surgery Feature Envy Data Clumps Primitive Obsession Switch Statements Parallel Inheritance Hierarchies Lazy Class Speculative Generality Temporary Field Message Chains Middle Man Inappropriate Intimacy Alternative Classes with Different Interfaces Incomplete Library Class Data Class Refused Bequest Comments
to a method Exact code in sibling class => Re-factor to a method in the parent class Similar code => Re-factor to a method with parameters Duplicate code in different classes => Use a trait Use the Rule of Three!
are harder to understand. Shorter methods mean more methods, specifically single use methods. Single use methods are NOT a bad thing! Makes your code more readable!
much responsibility and it can quickly become too large. Look for large numbers of properties and public methods. Refactoring opportunity: Look for name chunks. Frontend classes can benefit from domain classes to simplify. Lots of protected or private methods is generally ok.
needed yet. Don’t do it. Waste of time. You can’t see in the future! Increases complexity, you have to work around it. If by chance you actually use it later, it’s unlikely that you did it right.
A class that is stubbed out but not completed. Sometimes the result of a lot of refactoring and it just doesn't do much anymore. Get rid of it if it’s not worth having!
properties, getters and setters only. Not worth the extra work involved to interact with. A class needs to actually do something with it's data. Get rid of it!
be used. But sometimes they are overused or used to mask another code smell. Example: In-line comment that explains the line below it. "Comments are often used as a deodorant.” Re-write so that a human can actually understand it.
List Divergent Change Shotgun Surgery Feature Envy Data Clumps Primitive Obsession Switch Statements Parallel Inheritance Hierarchies Lazy Class Speculative Generality Temporary Field Message Chains Middle Man Inappropriate Intimacy Alternative Classes with Different Interfaces Incomplete Library Class Data Class Refused Bequest Comments