-
-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
Problem
- Without native types, not specifying the template type causes PHPStan to treat it as
mixed. As a consequence, incorrect parameter types will not be reported. See https://phpstan.org/r/6e9ccffd-23c4-4062-a4f7-20fcb6337cfb for an example. - While templates generally work well for general types, they do not for constant types as used in
functionMap.php. As soon as the value of a constant type is modified (e.g. through sanitisation), its type (for constant types the value itself) no longer is equal to that (template) type. See https://phpstan.org/r/42bbacae-fb55-46dc-93d8-2067d709d7c5 for an example.
Possible solutions for issue #2
- Remove the function from the stubs (and optionally add it as a dynamic return type via szepeviktor/phpstan-wordpress).
- Generalise the return type in
php-stubs/wordpress-stubs(and optionally add more complex logic as a dynamic return type via szepeviktor/phpstan-wordpress).
Affected functions
_wp_json_sanity_check(): I suggest removing it and not adding it to szepeviktor/phpstan-wordpress as it is a pseudo-private function anyways.addslashes_gpc(),wp_slash(),wp_unslash(),stripslashes_deep(),stripslashes_from_strings_only()rawurlencode_deep(),urldecode_deep(),urlencode_deep()sanitize_category(),sanitize_post(),sanitize_term()
Solutions for issue #1
Specify types if any types remain unspecified after fixing issue #2.
szepeviktor
Metadata
Metadata
Assignees
Labels
No labels