Commit fb532ba
committed
Code Quality: Add PHPStan conditional return types to the slashing functions.
Adds `@phpstan-` prefixed generics and conditional return types to `map_deep()`, `stripslashes_from_strings_only()`, `stripslashes_deep()`, `wp_slash()`, `wp_unslash()`, and `add_magic_quotes()`. Static analysis now knows that a `string` passed to the slashing functions yields a `string`, and an `array` yields an `array`; this is something the plain `@return` tags could not express, and which caused `wp_unslash()` to widen its callers' types to `array|string` even after an `is_array()` guard.
The returns are conditional rather than a bare `T` for two reasons: `map_deep()`'s callback may change the type of every leaf, and the slashing functions rewrite string contents, so a literal-string type cannot survive.
Developed in WordPress#12455.
See #64898.
git-svn-id: https://develop.svn.wordpress.org/trunk@62672 602fd350-edb4-49c9-b593-d223f7449a821 parent d6dd2e5 commit fb532ba
2 files changed
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2848 | 2848 | | |
2849 | 2849 | | |
2850 | 2850 | | |
| 2851 | + | |
| 2852 | + | |
| 2853 | + | |
| 2854 | + | |
| 2855 | + | |
| 2856 | + | |
| 2857 | + | |
| 2858 | + | |
2851 | 2859 | | |
2852 | 2860 | | |
2853 | 2861 | | |
| |||
2860 | 2868 | | |
2861 | 2869 | | |
2862 | 2870 | | |
| 2871 | + | |
| 2872 | + | |
| 2873 | + | |
| 2874 | + | |
2863 | 2875 | | |
2864 | 2876 | | |
2865 | 2877 | | |
| |||
5170 | 5182 | | |
5171 | 5183 | | |
5172 | 5184 | | |
| 5185 | + | |
| 5186 | + | |
| 5187 | + | |
| 5188 | + | |
5173 | 5189 | | |
5174 | 5190 | | |
5175 | 5191 | | |
| |||
5811 | 5827 | | |
5812 | 5828 | | |
5813 | 5829 | | |
| 5830 | + | |
| 5831 | + | |
| 5832 | + | |
| 5833 | + | |
| 5834 | + | |
| 5835 | + | |
| 5836 | + | |
| 5837 | + | |
5814 | 5838 | | |
5815 | 5839 | | |
5816 | 5840 | | |
| |||
5834 | 5858 | | |
5835 | 5859 | | |
5836 | 5860 | | |
| 5861 | + | |
| 5862 | + | |
| 5863 | + | |
| 5864 | + | |
| 5865 | + | |
| 5866 | + | |
| 5867 | + | |
| 5868 | + | |
5837 | 5869 | | |
5838 | 5870 | | |
5839 | 5871 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1289 | 1289 | | |
1290 | 1290 | | |
1291 | 1291 | | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
1292 | 1296 | | |
1293 | 1297 | | |
1294 | 1298 | | |
| |||
0 commit comments