Add slashit functions extension & fix stripslashes extension#299
Merged
szepeviktor merged 3 commits intoszepeviktor:2.xfrom Sep 11, 2025
Merged
Add slashit functions extension & fix stripslashes extension#299szepeviktor merged 3 commits intoszepeviktor:2.xfrom
szepeviktor merged 3 commits intoszepeviktor:2.xfrom
Conversation
Owner
|
It fails with phpstan-wordpress/composer.json Line 16 in 49b833d |
Contributor
Author
|
Since 2.1.18, there are no errors; the "errors" (nothing is incorrect--prior to 2.1.18 the types were simply wider) occurred because PHPStan improved its inference of |
Owner
|
Done. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.