-
Notifications
You must be signed in to change notification settings - Fork 95
Add rule for services modifying their internal state #11
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
Conversation
This is a VERY interesting PR, however I feel this would deserve it's own extension. I might incorporate some of the changes to facilitate easier extending of Service and/or ServiceMap classes with third party code. Stay tuned. 😊
I've made some refactoring in 0.10.2:
Servicenow implements theServiceDefinitioninterface.ServiceMapnow takes an array ofServiceDefinitions in the constructor.- The services are created by a factory implementing the
ServiceMapFactoryinterface. - The service map factory service is named in the
extension.neon.
Altogether this should allow you to override the service map factory with your own, returning your own implementation of the service definition interface, and do whatever you want from there. Let me know if you run into any issues.
Thanks @lookyman ! I will look into it and try to create an extension when I have some time 😊
With the arrival of different execution models like PHP-PM and Roadrunner, the container and related services can no longer be guaranteed to be destroyed on every request. A common source of bugs in these scenarios, are services that modify their state (for example changing internal attributes when a method is called) without resetting it at the end of the request, assuming the service will be destroyed and reset.
Static analysis presents a good opportunity to catch these bugs and help make applications or libraries compatible with these models. For this reason I'm proposing to add a rule that detects changes to a service's internal state, if its outside the constructor or the method injections defined in the config.