Skip to content

Commit 105674f

Browse files
Fix PHPStan errors in the WordPress 7.1 and 7.2 compat shims
- Check whether a List Item has inner blocks with `count()`, since `empty()` is never true for a `WP_Block_List` object. - Restore the array `media_type` and `mime_type` request parameters with `WP_REST_Request::set_param()`, which is what array access calls internally. - Drop the `isset()` check on `WP_Post::$post_date`, which is always set. - Document that `gutenberg_exclude_notes_from_comment_count_7_2()` always returns an int. Remove the 7 resolved entries from the PHPStan baseline. See #86088.
1 parent a20dc7d commit 105674f

5 files changed

Lines changed: 5 additions & 41 deletions

File tree

‎lib/compat/wordpress-7.1/block-bindings.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function gutenberg_restore_list_item_inner_blocks_after_binding( $block_content,
7070
return $block_content;
7171
}
7272

73-
if ( ! $instance instanceof WP_Block || empty( $instance->inner_blocks ) ) {
73+
if ( ! $instance instanceof WP_Block || 0 === count( $instance->inner_blocks ) ) {
7474
return $block_content;
7575
}
7676

‎lib/compat/wordpress-7.1/class-gutenberg-rest-attachments-controller-7-1.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ protected function prepare_items_query( $prepared_args = array(), $request = nul
5050

5151
// Restore the array parameters to the request.
5252
if ( null !== $media_type_array ) {
53-
$request['media_type'] = $media_type_array;
53+
$request->set_param( 'media_type', $media_type_array );
5454
}
5555

5656
if ( null !== $mime_type_array ) {
57-
$request['mime_type'] = $mime_type_array;
57+
$request->set_param( 'mime_type', $mime_type_array );
5858
}
5959

6060
if ( empty( $query_args['post_status'] ) ) {

‎lib/compat/wordpress-7.1/rest-api.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function gutenberg_add_date_wp_template_schema() {
3535
'get_callback' => function ( $item ) {
3636
if ( ! empty( $item['wp_id'] ) ) {
3737
$post = get_post( $item['wp_id'] );
38-
if ( $post && isset( $post->post_date ) ) {
38+
if ( $post ) {
3939
return mysql_to_rfc3339( $post->post_date );
4040
}
4141
}

‎lib/compat/wordpress-7.2/note-reactions.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ function gutenberg_hide_note_from_comment_list_table_7_2( $args ) {
172172
* @param int|null $new_count The new comment count. Default null.
173173
* @param int $old_count The old comment count.
174174
* @param int $post_id Post ID.
175-
* @return int|null The modified comment count.
175+
* @return int The modified comment count.
176176
*/
177177
function gutenberg_exclude_notes_from_comment_count_7_2( $new_count, $old_count, $post_id ) {
178178
global $wpdb;

‎tools/phpstan/baseline.neon‎

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -204,36 +204,12 @@ parameters:
204204
count: 1
205205
path: ../../lib/client-assets.php
206206

207-
-
208-
message: '#^Property WP_Block\:\:\$inner_blocks \(WP_Block_List\) in empty\(\) is not falsy\.$#'
209-
identifier: empty.property
210-
count: 1
211-
path: ../../lib/compat/wordpress-7.1/block-bindings.php
212-
213207
-
214208
message: '#^Parameter \#1 \$query of method WP_HTML_Tag_Processor\:\:next_tag\(\) expects array\{tag_name\?\: string\|null, match_offset\?\: int\|null, class_name\?\: string\|null, tag_closers\?\: string\|null\}\|null, ''SPAN'' given\.$#'
215209
identifier: argument.type
216210
count: 1
217211
path: ../../lib/compat/wordpress-7.1/block-comments.php
218212

219-
-
220-
message: '#^Cannot assign offset ''media_type'' to WP_REST_Request\.$#'
221-
identifier: offsetAssign.dimType
222-
count: 1
223-
path: ../../lib/compat/wordpress-7.1/class-gutenberg-rest-attachments-controller-7-1.php
224-
225-
-
226-
message: '#^Cannot assign offset ''mime_type'' to WP_REST_Request\.$#'
227-
identifier: offsetAssign.dimType
228-
count: 1
229-
path: ../../lib/compat/wordpress-7.1/class-gutenberg-rest-attachments-controller-7-1.php
230-
231-
-
232-
message: '#^WP_REST_Request does not accept array\<mixed, mixed\>\.$#'
233-
identifier: offsetAssign.valueType
234-
count: 2
235-
path: ../../lib/compat/wordpress-7.1/class-gutenberg-rest-attachments-controller-7-1.php
236-
237213
-
238214
message: '#^Strict comparison using \!\=\= between array\{\} and non\-empty\-array\<mixed, mixed\> will always evaluate to true\.$#'
239215
identifier: notIdentical.alwaysTrue
@@ -252,18 +228,6 @@ parameters:
252228
count: 1
253229
path: ../../lib/compat/wordpress-7.1/icons.php
254230

255-
-
256-
message: '#^Property WP_Post\:\:\$post_date \(string\) in isset\(\) is not nullable\.$#'
257-
identifier: isset.property
258-
count: 1
259-
path: ../../lib/compat/wordpress-7.1/rest-api.php
260-
261-
-
262-
message: '#^Function gutenberg_exclude_notes_from_comment_count_7_2\(\) never returns null so it can be removed from the return type\.$#'
263-
identifier: return.unusedType
264-
count: 1
265-
path: ../../lib/compat/wordpress-7.2/note-reactions.php
266-
267231
-
268232
message: '#^Method WP_Sync_Save_Server\:\:handle_request\(\) should return WP_Error\|WP_REST_Response but returns array\.$#'
269233
identifier: return.type

0 commit comments

Comments
 (0)