Improve return type of base64_decode()#4492
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.
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.
Yeah, I'm inclining not doing this at all.
There was a problem hiding this comment.
Would a length-limit help?
There was a problem hiding this comment.
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