Skip to content

Commit a190602

Browse files
committed
Code Quality: Use decimal-int-string for integer strings.
PHPStan 2.2.0 introduced the `decimal-int-string` type for a string in canonical decimal integer form, such as `'123'` or `'-5'`, which is exactly what casting an integer to a string produces. For historical reasons, WordPress passes many integers around as strings, since that is what MySQL returns for integer columns. These had been typed as `numeric-string`, which also admits floats, exponents, and leading zeros or whitespace. The narrower `decimal-int-string` type is now used for object IDs, `COUNT(*)` results, and the integer columns exposed on the core object classes. The `numeric-string` type is kept where a value can be zero-padded or fractional, such as date parts and EXIF image metadata, and for now in `wp_unique_id()` and `wp_unique_prefixed_id()` due to a PHPStan issue. Developed in WordPress#16013. Follow-up to r62437, r62640, r62717, r62822, r63488, r63618, r65269, r65527. See #65817. git-svn-id: https://develop.svn.wordpress.org/trunk@65534 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ce5226f commit a190602

16 files changed

Lines changed: 87 additions & 87 deletions

‎src/wp-includes/category.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
* @phpstan-return (
2727
* $args is array{ fields: 'count', ... }
28-
* ? list<0|numeric-string>
28+
* ? list<0|decimal-int-string>
2929
* : (
3030
* $args is array{ fields: 'names'|'slugs', ... }
3131
* ? list<string>

‎src/wp-includes/class-wp-comment.php‎

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,44 @@
1616
*
1717
* @since 4.4.0
1818
*
19-
* @property-read numeric-string|''|null $post_author
20-
* @property-read string|null $post_date
21-
* @property-read string|null $post_date_gmt
22-
* @property-read string|null $post_content
23-
* @property-read string|null $post_title
24-
* @property-read string|null $post_excerpt
25-
* @property-read non-empty-string|null $post_status
26-
* @property-read non-empty-string|null $comment_status
27-
* @property-read non-empty-string|null $ping_status
28-
* @property-read string|null $post_name
29-
* @property-read string|null $to_ping
30-
* @property-read string|null $pinged
31-
* @property-read string|null $post_modified
32-
* @property-read string|null $post_modified_gmt
33-
* @property-read string|null $post_content_filtered
34-
* @property-read non-negative-int|null $post_parent
35-
* @property-read string|null $guid
36-
* @property-read int|null $menu_order
37-
* @property-read non-empty-string|null $post_type
38-
* @property-read string|null $post_mime_type
39-
* @property-read numeric-string|null $comment_count
19+
* @property-read decimal-int-string|''|null $post_author
20+
* @property-read string|null $post_date
21+
* @property-read string|null $post_date_gmt
22+
* @property-read string|null $post_content
23+
* @property-read string|null $post_title
24+
* @property-read string|null $post_excerpt
25+
* @property-read non-empty-string|null $post_status
26+
* @property-read non-empty-string|null $comment_status
27+
* @property-read non-empty-string|null $ping_status
28+
* @property-read string|null $post_name
29+
* @property-read string|null $to_ping
30+
* @property-read string|null $pinged
31+
* @property-read string|null $post_modified
32+
* @property-read string|null $post_modified_gmt
33+
* @property-read string|null $post_content_filtered
34+
* @property-read non-negative-int|null $post_parent
35+
* @property-read string|null $guid
36+
* @property-read int|null $menu_order
37+
* @property-read non-empty-string|null $post_type
38+
* @property-read string|null $post_mime_type
39+
* @property-read decimal-int-string|null $comment_count
4040
*
4141
* @phpstan-type Data_Array array{
42-
* comment_ID: numeric-string,
43-
* comment_post_ID: numeric-string,
42+
* comment_ID: decimal-int-string,
43+
* comment_post_ID: decimal-int-string,
4444
* comment_author: string,
4545
* comment_author_email: string,
4646
* comment_author_url: string,
4747
* comment_author_IP: string,
4848
* comment_date: non-empty-string,
4949
* comment_date_gmt: non-empty-string,
5050
* comment_content: string,
51-
* comment_karma: numeric-string,
51+
* comment_karma: decimal-int-string,
5252
* comment_approved: non-empty-string,
5353
* comment_agent: string,
5454
* comment_type: string,
55-
* comment_parent: numeric-string,
56-
* user_id: numeric-string,
55+
* comment_parent: decimal-int-string,
56+
* user_id: decimal-int-string,
5757
* ...
5858
* }
5959
*/
@@ -68,7 +68,7 @@ final class WP_Comment {
6868
*
6969
* @since 4.4.0
7070
* @var string|int
71-
* @phpstan-var numeric-string|int
71+
* @phpstan-var decimal-int-string|int
7272
*/
7373
public $comment_ID;
7474

@@ -80,7 +80,7 @@ final class WP_Comment {
8080
*
8181
* @since 4.4.0
8282
* @var string|int
83-
* @phpstan-var numeric-string|int
83+
* @phpstan-var decimal-int-string|int
8484
*/
8585
public $comment_post_ID = '0';
8686

@@ -149,7 +149,7 @@ final class WP_Comment {
149149
*
150150
* @since 4.4.0
151151
* @var string
152-
* @phpstan-var numeric-string
152+
* @phpstan-var decimal-int-string
153153
*/
154154
public $comment_karma = '0';
155155

@@ -196,7 +196,7 @@ final class WP_Comment {
196196
*
197197
* @since 4.4.0
198198
* @var string
199-
* @phpstan-var numeric-string
199+
* @phpstan-var decimal-int-string
200200
*/
201201
public $comment_parent = '0';
202202

@@ -207,7 +207,7 @@ final class WP_Comment {
207207
*
208208
* @since 4.4.0
209209
* @var string
210-
* @phpstan-var numeric-string
210+
* @phpstan-var decimal-int-string
211211
*/
212212
public $user_id = '0';
213213

@@ -253,7 +253,7 @@ final class WP_Comment {
253253
* @global wpdb $wpdb WordPress database abstraction object.
254254
*
255255
* @param int $id Comment ID.
256-
* @phpstan-param int|numeric-string $id
256+
* @phpstan-param int|decimal-int-string $id
257257
* @return WP_Comment|false Comment object, otherwise false.
258258
*/
259259
public static function get_instance( $id ) {

‎src/wp-includes/class-wp-network.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @property string $blog_id
2323
* @property int $site_id
2424
*
25-
* @phpstan-property numeric-string $blog_id
25+
* @phpstan-property decimal-int-string $blog_id
2626
*/
2727
#[AllowDynamicProperties]
2828
class WP_Network {
@@ -64,7 +64,7 @@ class WP_Network {
6464
*
6565
* @since 4.4.0
6666
* @var string
67-
* @phpstan-var numeric-string
67+
* @phpstan-var decimal-int-string
6868
*/
6969
private $blog_id = '0';
7070

‎src/wp-includes/class-wp-post.php‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
* @phpstan-type Data_Array array{
2222
* ID: non-negative-int,
23-
* post_author: numeric-string|'',
23+
* post_author: decimal-int-string|'',
2424
* post_date: string,
2525
* post_date_gmt: string,
2626
* post_content: string,
@@ -41,7 +41,7 @@
4141
* menu_order: int,
4242
* post_type: non-empty-string,
4343
* post_mime_type: string,
44-
* comment_count: numeric-string,
44+
* comment_count: decimal-int-string,
4545
* filter: 'raw'|'edit'|'db'|'display'|'attribute'|'js'|'sample'|null,
4646
* ancestors: list<non-negative-int>,
4747
* page_template: string,
@@ -70,7 +70,7 @@ final class WP_Post {
7070
*
7171
* @since 3.5.0
7272
* @var string
73-
* @phpstan-var numeric-string|''
73+
* @phpstan-var decimal-int-string|''
7474
*/
7575
public $post_author = '0';
7676

@@ -246,7 +246,7 @@ final class WP_Post {
246246
*
247247
* @since 3.5.0
248248
* @var string
249-
* @phpstan-var numeric-string
249+
* @phpstan-var decimal-int-string
250250
*/
251251
public $comment_count = '0';
252252

@@ -274,7 +274,7 @@ final class WP_Post {
274274
* @param int $post_id Post ID.
275275
* @return WP_Post|false Post object, false otherwise.
276276
*
277-
* @phpstan-param int|numeric-string $post_id
277+
* @phpstan-param int|decimal-int-string $post_id
278278
*/
279279
public static function get_instance( $post_id ) {
280280
global $wpdb;

‎src/wp-includes/class-wp-site.php‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @property int|string|false $post_count
2323
* @property string $home
2424
*
25-
* @phpstan-property int|numeric-string|false $post_count
25+
* @phpstan-property int|decimal-int-string|false $post_count
2626
*/
2727
#[AllowDynamicProperties]
2828
final class WP_Site {
@@ -36,7 +36,7 @@ final class WP_Site {
3636
*
3737
* @since 4.5.0
3838
* @var string
39-
* @phpstan-var numeric-string
39+
* @phpstan-var decimal-int-string
4040
*/
4141
public $blog_id;
4242

@@ -66,7 +66,7 @@ final class WP_Site {
6666
*
6767
* @since 4.5.0
6868
* @var string
69-
* @phpstan-var numeric-string
69+
* @phpstan-var decimal-int-string
7070
*/
7171
public $site_id = '0';
7272

@@ -93,7 +93,7 @@ final class WP_Site {
9393
*
9494
* @since 4.5.0
9595
* @var string
96-
* @phpstan-var numeric-string
96+
* @phpstan-var decimal-int-string
9797
*/
9898
public $public = '1';
9999

@@ -104,7 +104,7 @@ final class WP_Site {
104104
*
105105
* @since 4.5.0
106106
* @var string
107-
* @phpstan-var numeric-string
107+
* @phpstan-var decimal-int-string
108108
*/
109109
public $archived = '0';
110110

@@ -118,7 +118,7 @@ final class WP_Site {
118118
*
119119
* @since 4.5.0
120120
* @var string
121-
* @phpstan-var numeric-string
121+
* @phpstan-var decimal-int-string
122122
*/
123123
public $mature = '0';
124124

@@ -129,7 +129,7 @@ final class WP_Site {
129129
*
130130
* @since 4.5.0
131131
* @var string
132-
* @phpstan-var numeric-string
132+
* @phpstan-var decimal-int-string
133133
*/
134134
public $spam = '0';
135135

@@ -140,7 +140,7 @@ final class WP_Site {
140140
*
141141
* @since 4.5.0
142142
* @var string
143-
* @phpstan-var numeric-string
143+
* @phpstan-var decimal-int-string
144144
*/
145145
public $deleted = '0';
146146

@@ -151,7 +151,7 @@ final class WP_Site {
151151
*
152152
* @since 4.5.0
153153
* @var string
154-
* @phpstan-var numeric-string
154+
* @phpstan-var decimal-int-string
155155
*/
156156
public $lang_id = '0';
157157

‎src/wp-includes/class-wp-term-query.php‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public function parse_query( $query = '' ) {
307307
*
308308
* @phpstan-return (
309309
* $query is array{ fields: 'count', ... }
310-
* ? 0|numeric-string
310+
* ? 0|decimal-int-string
311311
* : ( $query is array{ fields: 'ids'|'tt_ids', ... }
312312
* ? int[]
313313
* : ( $query is array{ fields: 'id=>parent', ... }
@@ -361,7 +361,7 @@ public function query( $query ) {
361361
* integer 0 when the queried parent term is not in the
362362
* taxonomy hierarchy.
363363
*
364-
* @phpstan-return 0|numeric-string|int[]|array<int, int>|string[]|array<int, string>|WP_Term[]
364+
* @phpstan-return 0|decimal-int-string|int[]|array<int, int>|string[]|array<int, string>|WP_Term[]
365365
*/
366366
public function get_terms() {
367367
global $wpdb;
@@ -821,7 +821,7 @@ public function get_terms() {
821821

822822
if ( 'count' === $_fields ) {
823823
// The request selects a single COUNT column, so it only returns null on a database error.
824-
/** @var numeric-string $count */
824+
/** @var decimal-int-string $count */
825825
$count = $wpdb->get_var( $this->request ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared
826826
if ( $args['cache_results'] ) {
827827
wp_cache_set_salted( $cache_key, $count, 'term-queries', $last_changed );

‎src/wp-includes/class-wp-user-request.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class WP_User_Request {
2121
*
2222
* @since 4.9.6
2323
* @var string
24-
* @phpstan-var numeric-string
24+
* @phpstan-var decimal-int-string
2525
*/
2626
public $user_id = '0';
2727

‎src/wp-includes/class-wp-user.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
* @property string $syntax_highlighting
4141
* @property string $use_ssl
4242
*
43-
* @phpstan-property numeric-string $user_status
44-
* @phpstan-property int|numeric-string|'' $user_level
43+
* @phpstan-property decimal-int-string $user_status
44+
* @phpstan-property int|decimal-int-string|'' $user_level
4545
*/
4646
#[AllowDynamicProperties]
4747
class WP_User {

‎src/wp-includes/comment.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ function delete_comment_meta( $comment_id, $meta_key, $meta_value = '' ) {
584584
* the type it was registered with, which may be an integer, float, or
585585
* boolean.
586586
*
587-
* @phpstan-param int|numeric-string $comment_id
587+
* @phpstan-param int|decimal-int-string $comment_id
588588
* @phpstan-return (
589589
* $key is ''|'0'
590590
* ? array<array-key, list<string>>|false

‎src/wp-includes/meta.php‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ function delete_metadata( $meta_type, $object_id, $meta_key, $meta_value = '', $
608608
* the type it was registered with, which may be an integer, float, or
609609
* boolean.
610610
*
611-
* @phpstan-param int|numeric-string $object_id
611+
* @phpstan-param int|decimal-int-string $object_id
612612
* @phpstan-return (
613613
* $meta_key is ''|'0'
614614
* ? ( $single is true
@@ -653,7 +653,7 @@ function get_metadata( $meta_type, $object_id, $meta_key = '', $single = false )
653653
* When `$meta_key` is not specified, the values are returned exactly as
654654
* they are held in the object cache, which means they are still serialized.
655655
*
656-
* @phpstan-param int|numeric-string $object_id
656+
* @phpstan-param int|decimal-int-string $object_id
657657
* @phpstan-return (
658658
* $meta_key is ''|'0'
659659
* ? array<array-key, list<string>>|false|null
@@ -747,7 +747,7 @@ function get_metadata_raw( $meta_type, $object_id, $meta_key = '', $single = fal
747747
* @return mixed An array of default values if `$single` is false.
748748
* The default value of the meta field if `$single` is true.
749749
*
750-
* @phpstan-param int|numeric-string $object_id
750+
* @phpstan-param int|decimal-int-string $object_id
751751
* @phpstan-return ( $single is true ? mixed : list<mixed> )
752752
*/
753753
function get_metadata_default( $meta_type, $object_id, $meta_key, $single = false ) {
@@ -857,7 +857,7 @@ function metadata_exists( $meta_type, $object_id, $meta_key ) {
857857
* @type string $user_id Optional. The object ID when the meta type is 'user'.
858858
* }
859859
*
860-
* @phpstan-param int|numeric-string $meta_id
860+
* @phpstan-param int|decimal-int-string $meta_id
861861
*/
862862
function get_metadata_by_mid( $meta_type, $meta_id ) {
863863
global $wpdb;
@@ -930,7 +930,7 @@ function get_metadata_by_mid( $meta_type, $meta_id ) {
930930
* @param string|false $meta_key Optional. You can provide a meta key to update it. Default false.
931931
* @return bool True on successful update, false on failure.
932932
*
933-
* @phpstan-param int|numeric-string $meta_id
933+
* @phpstan-param int|decimal-int-string $meta_id
934934
*/
935935
function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key = false ) {
936936
global $wpdb;
@@ -1057,7 +1057,7 @@ function update_metadata_by_mid( $meta_type, $meta_id, $meta_value, $meta_key =
10571057
* @param int|string $meta_id ID for a specific meta row.
10581058
* @return bool True on successful delete, false on failure.
10591059
*
1060-
* @phpstan-param int|numeric-string $meta_id
1060+
* @phpstan-param int|decimal-int-string $meta_id
10611061
*/
10621062
function delete_metadata_by_mid( $meta_type, $meta_id ) {
10631063
global $wpdb;

0 commit comments

Comments
 (0)