Skip to content

Commit 80d2e42

Browse files
committed
Code Quality: Resolve the varTag.noVariable PHPStan errors.
PHPStan reports `varTag.noVariable` for a `@var` tag that names no variable and is not above a local variable assignment, since such a tag has nothing to apply to. Eight of these were above `define()` calls, which declare no variable, and they are removed. No type information is lost, since PHPStan reads the types of the constants that vary by environment from `dynamicConstantNames` and infers the others from their values. The tag for `CUSTOM_TAGS` was also wrong, as it described the constant as an array of tags rather than a flag, so its docblock now explains that defining it as `true` uses the KSES globals in place of the defaults. The other nine were above assignments to `WP_Query` properties, where they were added in r49700 to help IDEs narrow the union property types. Neither PHPStan nor !PhpStorm applied them, and PHPStan already narrows each property from the assigned value, so they are removed as well. Two similar tags above local variables in `WP_Query::get_posts()` are also removed, since they only overrode the types PHPStan infers, one of them with a less precise type. This empties the baseline, so it is removed. Developed in #15449. Follow-up to r49700, r49927, r63020. Props mukesh27, westonruter. See #66739. git-svn-id: https://develop.svn.wordpress.org/trunk@65794 602fd350-edb4-49c9-b593-d223f7449a82
1 parent a786491 commit 80d2e42

9 files changed

Lines changed: 2 additions & 85 deletions

File tree

‎src/wp-admin/install.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
* We are installing WordPress.
2828
*
2929
* @since 1.5.1
30-
* @var bool
3130
*/
3231
define( 'WP_INSTALLING', true );
3332

‎src/wp-admin/profile.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* This is a profile page.
1111
*
1212
* @since 2.5.0
13-
* @var bool
1413
*/
1514
define( 'IS_PROFILE_PAGE', true );
1615

‎src/wp-admin/upgrade.php‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
* We are upgrading WordPress.
1111
*
1212
* @since 1.5.1
13-
* @var bool
1413
*/
1514
define( 'WP_INSTALLING', true );
1615

‎src/wp-cron.php‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636

3737
/**
3838
* Tell WordPress the cron task is running.
39-
*
40-
* @var bool
4139
*/
4240
define( 'DOING_CRON', true );
4341

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

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,7 +2921,6 @@ public function get_posts() {
29212921
_prime_comment_caches( $comment_ids );
29222922

29232923
// Convert to WP_Comment.
2924-
/** @var WP_Comment[] */
29252924
$this->comments = array_map( 'get_comment', $comment_ids );
29262925
$this->comment_count = count( $this->comments );
29272926

@@ -3289,7 +3288,6 @@ public function get_posts() {
32893288

32903289
if ( $cached_results ) {
32913290
$cache_found = true;
3292-
/** @var int[] */
32933291
$post_ids = array_map( 'intval', $cached_results['posts'] );
32943292

32953293
$this->post_count = count( $post_ids );
@@ -3327,7 +3325,6 @@ public function get_posts() {
33273325
return $post_parents;
33283326
} else {
33293327
_prime_post_caches( $post_ids, $query_vars['update_post_term_cache'], $query_vars['update_post_meta_cache'] );
3330-
/** @var WP_Post[] */
33313328
$this->posts = array_map( 'get_post', $post_ids );
33323329
}
33333330
}
@@ -3337,7 +3334,6 @@ public function get_posts() {
33373334
if ( 'ids' === $query_vars['fields'] ) {
33383335
$this->posts ??= $wpdb->get_col( $this->request );
33393336

3340-
/** @var int[] */
33413337
$this->posts = array_map( 'intval', $this->posts );
33423338
$this->post_count = count( $this->posts );
33433339
$this->set_found_posts( $query_vars, $limits );
@@ -3361,7 +3357,6 @@ public function get_posts() {
33613357
$this->post_count = count( $this->posts );
33623358
$this->set_found_posts( $query_vars, $limits );
33633359

3364-
/** @var int[] */
33653360
$post_parents = array();
33663361
$post_ids = array();
33673362
$post_parents_cache = array();
@@ -3468,7 +3463,6 @@ public function get_posts() {
34683463

34693464
// Convert to WP_Post objects.
34703465
if ( $this->posts ) {
3471-
/** @var WP_Post[] */
34723466
$this->posts = array_map( 'get_post', $this->posts );
34733467
}
34743468

@@ -3591,7 +3585,6 @@ public function get_posts() {
35913585
_prime_comment_caches( $comment_ids );
35923586

35933587
// Convert to WP_Comment.
3594-
/** @var WP_Comment[] */
35953588
$this->comments = array_map( 'get_comment', $comment_ids );
35963589
$this->comment_count = count( $this->comments );
35973590
}
@@ -3665,7 +3658,6 @@ public function get_posts() {
36653658
if ( $this->posts ) {
36663659
$this->post_count = count( $this->posts );
36673660

3668-
/** @var WP_Post[] */
36693661
$this->posts = array_map( 'get_post', $this->posts );
36703662

36713663
if ( $query_vars['cache_results'] ) {
@@ -3677,7 +3669,6 @@ public function get_posts() {
36773669
}
36783670
}
36793671

3680-
/** @var WP_Post */
36813672
$this->post = reset( $this->posts );
36823673
} else {
36833674
$this->post_count = 0;
@@ -3771,7 +3762,6 @@ public function next_post() {
37713762

37723763
++$this->current_post;
37733764

3774-
/** @var WP_Post */
37753765
$this->post = $this->posts[ $this->current_post ];
37763766
return $this->post;
37773767
}
@@ -3918,7 +3908,6 @@ public function rewind_posts() {
39183908
public function next_comment() {
39193909
++$this->current_comment;
39203910

3921-
/** @var WP_Comment */
39223911
$this->comment = $this->comments[ $this->current_comment ];
39233912
return $this->comment;
39243913
}

‎src/wp-includes/kses.php‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@
3131
*/
3232

3333
/**
34-
* Specifies the default allowable HTML tags.
34+
* Whether to use custom allowed HTML tags from the KSES globals.
3535
*
3636
* Using `CUSTOM_TAGS` is not recommended and should be considered deprecated. The
3737
* {@see 'wp_kses_allowed_html'} filter is more powerful and supplies context.
3838
*
39-
* When using this constant, make sure to set all of these globals to arrays:
39+
* To use custom tags, define this constant as `true` and set all of these globals to arrays:
4040
*
4141
* - `$allowedposttags`
4242
* - `$allowedtags`
@@ -45,8 +45,6 @@
4545
*
4646
* @see wp_kses_allowed_html()
4747
* @since 1.2.0
48-
*
49-
* @var array[]|false Array of default allowable HTML tags, or false to use the defaults.
5048
*/
5149
if ( ! defined( 'CUSTOM_TAGS' ) ) {
5250
define( 'CUSTOM_TAGS', false );

‎src/wp-includes/rest-api.php‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
/**
1111
* Version number for our API.
12-
*
13-
* @var string
1412
*/
1513
define( 'REST_API_VERSION', '2.0' );
1614

@@ -485,7 +483,6 @@ function rest_api_loaded() {
485483
* Whether this is a REST Request.
486484
*
487485
* @since 4.4.0
488-
* @var bool
489486
*/
490487
define( 'REST_REQUEST', true );
491488

‎src/xmlrpc.php‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
/**
99
* Whether this is an XML-RPC Request.
10-
*
11-
* @var bool
1210
*/
1311
define( 'XMLRPC_REQUEST', true );
1412

‎tests/phpstan/baselines/varTag.noVariable.neon‎

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)