Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Introduction of phpstan #57
base: master
Are you sure you want to change the base?
Introduction of phpstan #57
Changes from all commits
ff304a2
da38ad5
d638ed2
faed10a
7687fce
cb1c7f9
1d3608f
77567a7
fe7709e
0995b5e
25d32c2
f5153c1
3e52f99
f005470
641b840
9fec908
6eecb46
81f58ff
d5064db
13d9411
aa4c629
5ceef1a
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of this thing. This is designed to make PHPStan pass more easily, not to make the code safer. Take this example:
Using that plugin, this passes as-is. Nice! Nice?
What if you have code that does:
Now, the
filterTitle()
function will return an integer, withstring
declared as the return type, resulting in a fatal error that the static analysis did not catch.One might say that the culprit is the
add_filter
that returned an integer where a string was expected. And that is true but was static analysis able to tell whoever wrote thatadd_filter
they were doing something wrong? No, not at all.In short, the behavior above is clearly a logic mistake that a static analysis could catch, but using that plugin, it is hiding from us.
Without using that plugin, PHPStan would report an error on
filterTitle
, telling that it returns mixed where a string is expected. That might be annoying but it is the absolute truth.apply_filters
makes our function returnmixed
, and if we use a plugin to "mock" it returns a string, then we are not working to make our code better, we are just making the tool happy hiding a whole set of errors.The goal is not to have the CI green; the goal is to catch possible errors. Otherwise, for our unit tests, we could use a tool like https://github.com/hugues-m/phpunit-vw to ensure we never have failing tests, right?
If you don't have that plugin, you have two possibilities. Either you do something like this:
Or you do:
In the first case, you are aiming at stability and defensiveness. Which is great for public APIs.
In the second case, you are making it explicit that you're trusting the filter consumers. This has the same net effect of using the PHPStan plugin (if someone returns an integer from the filter, it breaks) but:
Having a tool that hides all of that from you, might look nice at first because the checks pass more easily, but that is not the goal, right?
This file was deleted.