Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Closed
dnna wants to merge 9 commits into phpstan:master from dnna:modifiedstate

Conversation

@dnna
Copy link

@dnna dnna commented Sep 11, 2018

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.

COil reacted with thumbs up emoji
Copy link
Collaborator

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. 😊

dnna reacted with hooray emoji

Copy link
Collaborator

lookyman commented Oct 30, 2018
edited
Loading

I've made some refactoring in 0.10.2:

  • Service now implements the ServiceDefinition interface.
  • ServiceMap now takes an array of ServiceDefinitions in the constructor.
  • The services are created by a factory implementing the ServiceMapFactory interface.
  • 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.

Copy link
Author

dnna commented Nov 1, 2018

Thanks @lookyman ! I will look into it and try to create an extension when I have some time 😊

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

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /