Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sniff to disallow set methods. #111

Open
bmitch opened this issue Sep 2, 2017 · 0 comments
Open

Sniff to disallow set methods. #111

bmitch opened this issue Sep 2, 2017 · 0 comments

Comments

@bmitch
Copy link
Owner

bmitch commented Sep 2, 2017

From @Exadra37

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant