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. #93

Closed
Exadra37 opened this issue Sep 2, 2017 · 4 comments
Closed

Sniff to disallow set methods. #93

Exadra37 opened this issue Sep 2, 2017 · 4 comments

Comments

@Exadra37
Copy link

Exadra37 commented Sep 2, 2017

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.

@bmitch
Copy link
Owner

bmitch commented Sep 2, 2017

Sorry @Exadra37 I think you have the wrong project. Were you thinking of https://github.com/bmitch/Codor ?

@bmitch bmitch closed this as completed Sep 2, 2017
@bmitch
Copy link
Owner

bmitch commented Sep 2, 2017

See #93

See bmitch/Codor#111

@Exadra37
Copy link
Author

Exadra37 commented Sep 2, 2017

@bmitch this is not Gitlab where we can cross reference issues between repos... your last comment points to itself ;)

Sorry to open the issue in the wrong repo :(

@bmitch
Copy link
Owner

bmitch commented Sep 2, 2017

Thanks @Exadra37 I updated it 😃

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

No branches or pull requests

2 participants