You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using set methods in a class is not advised, because:
if the class is instantiated and we forget to call the set methods it may work or not and cause side effects. Plus we may need to call them in the correct order.
if you need to inject Collaborators they must be strictly injected via constructor and any other values needed by the class should be passed as arguments to the method being called, preferable using Immutable Value Objects(the only exception to not inject an object via constructor).
objects are passed by reference in Php, therefore when the object is passed around any call to the set method will affect all places where the object is being used. This can cause undesired bugs, that sometimes are hard to track.
I can continue with more cases why we should not use set methods, but I think the above 3 ones are strong enough to justify the sniff.
Thanks for your excellent work.
The text was updated successfully, but these errors were encountered:
From @Exadra37
Using set methods in a class is not advised, because:
I can continue with more cases why we should not use set methods, but I think the above 3 ones are strong enough to justify the sniff.
Thanks for your excellent work.
The text was updated successfully, but these errors were encountered: