-
Notifications
You must be signed in to change notification settings - Fork 551
Improve return type of base64_decode() #4492
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
base: 2.1.x
Are you sure you want to change the base?
Conversation
- Detect when the result cannot be false - Correctly treat non-boolean $strict parameter
2fdb743 to
1b54776
Compare
|
This improves things a bit too much as it breaks analysis of PHPStan itself 😀 The base64 call inside the codebase meant to obfuscate a string so that we don't need to baseline related errors. But now we can un-obfuscate it and actually baseline the errors. |
| $isValidBase64 = TrinaryLogic::lazyExtremeIdentity( | ||
| $constantStrings, | ||
| static function (ConstantStringType $constantString): TrinaryLogic { | ||
| $isValid = base64_decode($constantString->getValue(), true) !== false; |
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.
base64-decoding any string from within the codebase could skyrocket memory needed by phpstan analysis.
e.g. some codebases contain multi-megabyte base64 representations of images
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.
Yeah, I'm inclining not doing this at all.
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.
Would a length-limit help?
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 really not sure why would we want to decode literal strings passed to this method at all.
Fix handling of non-bools as
$strictparameter and omitfalsefrom return type when$stringis valid base64.This is useful when constant binary strings are required in code, e.g.:
Related to phpstan/phpstan#7866