Repository navigation
Commit 58911ba
committed
Date/Time: Correct argument types in
The PHPStan baseline held eight `argument.type` errors for `WP_Date_Query`, caused by docblocks narrower than the input the methods actually handle and by an unused parameter. Since `build_value()` was introduced it has been documented as taking a string or an array, yet `build_time_query()` has always passed it integers or null. And when nested queries were added, `get_sql_for_subquery()` passed an empty string for the `$parent_query` array that `get_sql_for_clause()` never reads.
No path of `build_mysql_datetime()` returns false, though its `@return` tag said otherwise. An unparseable string has always resulted in the Unix epoch, obtained by passing false as the timestamp to `gmdate()`. That fallback now passes 0 and is documented, and its test asserts the fixed value instead of computing it, which also corrects a comment claiming the test was time-dependent.
The PHPStan types also go further than the published `@param` tags in describing valid input. The comparison operator is limited to the ten accepted by `get_compare()`, which are put directly into SQL. Date values are limited to non-negative integers or numeric strings, because `absint()` would silently turn a negative value positive. Non-numeric values are still filtered out at runtime, so there is no change in behavior.
Developed in #15469.
Follow-up to r25139, r29923, r45876.
Props pwtyler, westonruter.
See #65817.
git-svn-id: https://develop.svn.wordpress.org/trunk@65262 602fd350-edb4-49c9-b593-d223f7449a82WP_Date_Query.1 parent a99e724 commit 58911ba
3 files changed
Lines changed: 28 additions & 30 deletions
File tree
- src/wp-includes
- tests
- phpstan/baselines
- phpunit/tests/date
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
| 52 | + | |
50 | 53 | | |
51 | 54 | | |
52 | 55 | | |
| |||
252 | 255 | | |
253 | 256 | | |
254 | 257 | | |
| 258 | + | |
| 259 | + | |
255 | 260 | | |
256 | 261 | | |
257 | 262 | | |
| |||
697 | 702 | | |
698 | 703 | | |
699 | 704 | | |
700 | | - | |
| 705 | + | |
701 | 706 | | |
702 | 707 | | |
703 | 708 | | |
| |||
808 | 813 | | |
809 | 814 | | |
810 | 815 | | |
811 | | - | |
812 | | - | |
| 816 | + | |
| 817 | + | |
813 | 818 | | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
814 | 822 | | |
815 | 823 | | |
816 | 824 | | |
| |||
873 | 881 | | |
874 | 882 | | |
875 | 883 | | |
876 | | - | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
877 | 895 | | |
878 | 896 | | |
879 | 897 | | |
| |||
922 | 940 | | |
923 | 941 | | |
924 | 942 | | |
925 | | - | |
| 943 | + | |
926 | 944 | | |
927 | 945 | | |
928 | 946 | | |
| |||
931 | 949 | | |
932 | 950 | | |
933 | 951 | | |
934 | | - | |
| 952 | + | |
935 | 953 | | |
936 | 954 | | |
937 | 955 | | |
| |||
958 | 976 | | |
959 | 977 | | |
960 | 978 | | |
| 979 | + | |
| 980 | + | |
961 | 981 | | |
962 | 982 | | |
963 | 983 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
708 | 708 | | |
709 | 709 | | |
710 | 710 | | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
716 | | - | |
717 | | - | |
718 | | - | |
719 | | - | |
720 | | - | |
721 | | - | |
722 | | - | |
723 | | - | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
729 | | - | |
730 | | - | |
731 | 711 | | |
732 | 712 | | |
733 | 713 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
524 | 524 | | |
525 | 525 | | |
526 | 526 | | |
527 | | - | |
528 | | - | |
529 | | - | |
530 | | - | |
| 527 | + | |
| 528 | + | |
531 | 529 | | |
532 | 530 | | |
533 | 531 | | |
| |||
0 commit comments