Description
Rule
Method chaining in class design MUST be avoided.
Reason
Source: Magento Technical Guidelines.
According to technical guidelines:
Application SHOULD be structured in compliance with the CQRS principle.
Good explanation of why method chaining contradicts this principal was described by Martin Fowler in the "Domain-Specific-Languages" book:
Command-query separation is an extremely valuable principle in programming, and I strongly encourage teams to use it. One of the consequences of using Method Chaining in internal DSLs is that it usually breaks this principle - each method alters state but returns an object to continue the chain. I have used many decibels disparaging people who don't follow command-query separation, and will do so again.
Suggested Implementation Direction
Detect return $this;
in methods.