Add slashit functions extension & fix stripslashes extension #299
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.
Adds a dynamic function return type extension for handling:
untrailingslashit()— removes trailing forward slashes and backslashes,trailingslashit()— adds a trailing slash after removing any trailing slashes,backslashit()— adds backslashes before letters and before a number at the start of a string.For (1) and (2), the extension uses the types PHPStan provides for
rtrim()and string concatenation.For (3), the extension traverses types, generalising constant strings to strings with accessory types, and replaces
numeric-string(backslashes will be added) andnon-empty-string(if it were'0', backslashes would be added) withnon-falsy-string.Fixes the
StripslashesFromStringsOnlyDynamicFunctionReturnTypeExtensionby letting PHPStan handle the type for non-constant string arguments (e.g. a non-falsy string might be'\\', which becomes''). Currently, PHPStan returnsstringfor calls tostripslashes(). If PHPStan ever decides thatstripslashes()should be, or is worth being, handled more granularly, this extension will align with that.