-
Notifications
You must be signed in to change notification settings - Fork 548
fix handling of JSON_THROW_ON_ERROR with optional bitwise flags
#1025
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
src/Type/BitwiseFlagAnalyser.php
Outdated
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.
extracted the duplicated logic of the 2 json extensions into this re-usable class - which should also work for other methods using INT-bitwise flags.
After this PR is merged, we can use this new service in other extensions which also do bitwise flag stuff
src/Type/BitwiseFlagAnalyser.php
Outdated
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.
the actual fix for the bug 6654 was the missing UnionType handling
ondrejmirtes
left a comment
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.
This needs to work on yes/no/maybe basis with TrinaryLogic.
- Yes - we know that
JSON_THROW_ON_ERRORis present - for example a constant integer or a constant reference. - No - we know that
JSON_THROW_ON_ERRORis not present - for examplestring, or a constant integer that doesn't include the value. - Maybe -
JSON_THROW_ON_ERRORmight be present - for exampleintormixedtype.
251f3d4 to
132ad93
Compare
|
reworked to use Trinary. added test-coverage. |
src/Type/BitwiseFlagAnalyser.php
Outdated
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.
Even if the constant is not known by the ReflectionProvider, we could support this case for AST-driven analysis. If the expression is ConstFetch of $constName or even a bitwise combination where one of the parts is $constName, we can return Yes.
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 am not sure what todo with this feedback.
do you mean we should add AST-driven analysis with this PR? or in a future PR?
when the ReflectionProvider doesn't know the constant, and we therefore cannot judge what the value-type of the constant is (is it a string? is it a int? which constant-int value has it), IMO we cannot analyse whether its contained in a given expression, can we? or would you judge the constant just by its name, no matter what the value is?
do you see this "constant is not know to the ReflectionProvider" as an essential case, or is it a edge case which can be done later?
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 think it's just about an if that could easily be added. If we ask BitwiseFlagHelper about a FOO_CONSTANT and we see the AST contains a ConstFetch of FOO_CONSTANT, we don't need to verify the value because we know it's the same thing.
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 think I figured it out
9a4dcdd to
1370ee2
Compare
44d6361 to
5412e18
Compare
|
Thank you. |
closes phpstan/phpstan#6654