Skip to content

Commit 240ab1b

Browse files
authored
PHPStan Level 5 (#220)
* Set PHPStan Level 5 * Corrects "Parameter #2 $silent of function deactivate_plugins expects bool, string given." * Solves "Parameter #1 of function esc_attr expects string, int given." * 3rd paramter for wp_validate_site_url should be a string * site__not_in should be int[] * Stronger typing for response->header() * Stringer typing when using ABSPATH * filter_input with FILTER_SANITIZE_NUMBER_INT sanitizes but returns still a string * Removed value false for the parameter media which will now default to 'all'
1 parent 4ba124a commit 240ab1b

File tree

8 files changed

+29
-28
lines changed

8 files changed

+29
-28
lines changed

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 4
2+
level: 5
33
paths:
44
- wp-multi-network/includes
55
- wpmn-loader.php

wp-multi-network/includes/classes/class-wp-ms-network-command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ function ( $file ) {
306306
if ( 'activate' === $action ) {
307307
activate_plugins( $plugin->file, '', $network_wide );
308308
} else {
309-
deactivate_plugins( $plugin->file, '', $network_wide );
309+
deactivate_plugins( $plugin->file, false, $network_wide );
310310
}
311311

312312
$this->active_output( $plugin->name, $plugin->file, $network_wide, 'activate' );

wp-multi-network/includes/classes/class-wp-ms-networks-admin.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function enqueue_scripts( $page = '' ) {
157157
return;
158158
}
159159

160-
wp_register_style( 'wp-multi-network', wpmn()->plugin_url . 'assets/css/wp-multi-network.css', array(), wpmn()->asset_version, false );
160+
wp_register_style( 'wp-multi-network', wpmn()->plugin_url . 'assets/css/wp-multi-network.css', array(), wpmn()->asset_version );
161161
wp_register_script( 'wp-multi-network', wpmn()->plugin_url . 'assets/js/wp-multi-network.js', array( 'jquery', 'post' ), wpmn()->asset_version, true );
162162

163163
wp_enqueue_style( 'wp-multi-network' );
@@ -351,7 +351,7 @@ public function route_save_handlers() {
351351
* @since 2.0.0
352352
*/
353353
public function page_edit_network() {
354-
$network_id = filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT );
354+
$network_id = (int) filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT );
355355
$network = $network_id ? get_network( $network_id ) : null;
356356

357357
add_meta_box( 'wpmn-edit-network-details', esc_html__( 'Details', 'wp-multi-network' ), 'wpmn_edit_network_details_metabox', get_current_screen()->id, 'normal', 'high', array( $network ) );
@@ -475,7 +475,7 @@ private function page_all_networks() {
475475
* @since 2.0.0
476476
*/
477477
private function page_move_site() {
478-
$site_id = filter_input( INPUT_GET, 'blog_id', FILTER_SANITIZE_NUMBER_INT );
478+
$site_id = (int) filter_input( INPUT_GET, 'blog_id', FILTER_SANITIZE_NUMBER_INT );
479479
$site = $site_id ? get_site( $site_id ) : null;
480480

481481
// Bail if invalid site ID.
@@ -548,7 +548,7 @@ private function page_move_site() {
548548
* @since 2.0.0
549549
*/
550550
private function page_delete_network() {
551-
$network_id = filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT );
551+
$network_id = (int) filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT );
552552
$network = $network_id ? get_network( $network_id ) : null;
553553

554554
// Bail if invalid network ID.
@@ -944,7 +944,7 @@ private function handle_add_network() {
944944
private function handle_update_network() {
945945

946946
// Sanitize network ID.
947-
$network_id = filter_input( INPUT_POST, 'network_id', FILTER_SANITIZE_NUMBER_INT );
947+
$network_id = (int) filter_input( INPUT_POST, 'network_id', FILTER_SANITIZE_NUMBER_INT );
948948

949949
// Bail if invalid network.
950950
if ( ! get_network( $network_id ) ) {
@@ -1006,8 +1006,8 @@ private function handle_update_network() {
10061006
private function handle_move_site() {
10071007

10081008
// Sanitize values.
1009-
$site_id = filter_input( INPUT_GET, 'blog_id', FILTER_SANITIZE_NUMBER_INT );
1010-
$new_network = filter_input( INPUT_POST, 'to', FILTER_SANITIZE_NUMBER_INT );
1009+
$site_id = (int) filter_input( INPUT_GET, 'blog_id', FILTER_SANITIZE_NUMBER_INT );
1010+
$new_network = (int) filter_input( INPUT_POST, 'to', FILTER_SANITIZE_NUMBER_INT );
10111011

10121012
// Bail if no site ID.
10131013
if ( empty( $site_id ) ) {
@@ -1075,7 +1075,7 @@ private function handle_reassign_sites() {
10751075
}
10761076

10771077
// Sanitize network ID.
1078-
$network_id = filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT );
1078+
$network_id = (int) filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT );
10791079

10801080
// Default to/from arrays.
10811081
$moving_to = array();
@@ -1130,7 +1130,7 @@ private function handle_reassign_sites() {
11301130
private function handle_delete_network() {
11311131

11321132
// Sanitize values.
1133-
$network_id = filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT );
1133+
$network_id = (int) filter_input( INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT );
11341134
$override = (bool) filter_input( INPUT_POST, 'override' );
11351135

11361136
// Attempt to delete network.

wp-multi-network/includes/classes/class-wp-ms-networks-list-table.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ public function column_cb( $network ) {
279279
}
280280

281281
?>
282-
<label class="screen-reader-text" for="network_<?php echo esc_attr( $network->id ); ?>">
282+
<label class="screen-reader-text" for="network_<?php echo esc_attr( strval( $network->id ) ); ?>">
283283
<?php
284284
printf(
285285
/* translators: %s: network name */
@@ -288,7 +288,7 @@ public function column_cb( $network ) {
288288
);
289289
?>
290290
</label>
291-
<input type="checkbox" id="network_<?php echo esc_attr( $network->id ); ?>" name="all_networks[]" value="<?php echo esc_attr( $network->id ); ?>">
291+
<input type="checkbox" id="network_<?php echo esc_attr( strval( $network->id ) ); ?>" name="all_networks[]" value="<?php echo esc_attr( strval( $network->id ) ); ?>">
292292
<?php
293293
}
294294

@@ -396,7 +396,7 @@ public function column_admins( $network ) {
396396
* @param WP_Network $network The current network object.
397397
*/
398398
public function column_id( $network ) {
399-
echo esc_html( $network->id );
399+
echo esc_html( strval( $network->id ) );
400400
}
401401

402402
/**

wp-multi-network/includes/classes/class-wp-ms-rest-networks-controller.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ public function get_items( $request ) {
193193
$networks[] = $this->prepare_response_for_collection( $data );
194194
}
195195

196-
$total_networks = (int) $query->found_networks;
197-
$max_pages = (int) $query->max_num_pages;
196+
$total_networks = $query->found_networks;
197+
$max_pages = $query->max_num_pages;
198198

199199
if ( $total_networks < 1 ) {
200200
// Out-of-bounds, run the query again without LIMIT for total count.
@@ -203,13 +203,13 @@ public function get_items( $request ) {
203203
$query = new WP_Network_Query();
204204
$prepared_args['count'] = true;
205205

206-
$total_networks = $query->query( $prepared_args );
207-
$max_pages = ceil( $total_networks / $request['per_page'] );
206+
$total_networks = (int) $query->query( $prepared_args );
207+
$max_pages = (int) ceil( $total_networks / $request['per_page'] );
208208
}
209209

210210
$response = rest_ensure_response( $networks );
211-
$response->header( 'X-WP-Total', $total_networks );
212-
$response->header( 'X-WP-TotalPages', $max_pages );
211+
$response->header( 'X-WP-Total', strval( $total_networks ) );
212+
$response->header( 'X-WP-TotalPages', strval( $max_pages ) );
213213

214214
$base = add_query_arg( $request->get_query_params(), rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ) );
215215

wp-multi-network/includes/functions.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,9 @@ function add_network( $args = array() ) {
616616
$upload_url = $upload_url . '/uploads';
617617

618618
$upload_dir = WP_CONTENT_DIR;
619-
if ( 0 === strpos( $upload_dir, ABSPATH ) ) {
620-
$upload_dir = substr( $upload_dir, strlen( ABSPATH ) );
619+
$needle = strval( ABSPATH );
620+
if ( 0 === strpos( $upload_dir, $needle ) ) {
621+
$upload_dir = substr( $upload_dir, strlen( $needle ) );
621622
}
622623
$upload_dir .= '/uploads';
623624

@@ -717,7 +718,7 @@ function update_network( $id, $domain, $path = '' ) {
717718
$path = wp_sanitize_site_path( $path );
718719

719720
// Bail if site URL is invalid.
720-
if ( ! wp_validate_site_url( $domain, $path, $site_id ) ) {
721+
if ( ! wp_validate_site_url( $domain, $path, strval( $site_id ) ) ) {
721722
/* translators: %s: site domain and path */
722723
return new WP_Error( 'blog_bad', sprintf( __( 'The site "%s" is invalid, not available, or already exists.', 'wp-multi-network' ), $domain . $path ) );
723724
}

wp-multi-network/includes/metaboxes/edit-network.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function wpmn_edit_network_new_site_metabox() {
8989
function wpmn_edit_network_assign_sites_metabox( $network = null ) {
9090
$to = get_sites(
9191
array(
92-
'site__not_in' => get_main_site_id( $network->id ),
92+
'site__not_in' => array( get_main_site_id( $network->id ) ),
9393
'network_id' => $network->id,
9494
)
9595
);
@@ -118,7 +118,7 @@ function wpmn_edit_network_assign_sites_metabox( $network = null ) {
118118

119119
<?php if ( ( (int) $site->network_id !== (int) $network->id ) && ! is_main_site_for_network( $site->id ) ) : ?>
120120

121-
<option value="<?php echo esc_attr( $site->id ); ?>">
121+
<option value="<?php echo esc_attr( strval( $site->id ) ); ?>">
122122
<?php echo esc_html( sprintf( '%1$s (%2$s%3$s)', $site->blogname, $site->domain, $site->path ) ); ?>
123123
</option>
124124

@@ -139,7 +139,7 @@ function wpmn_edit_network_assign_sites_metabox( $network = null ) {
139139

140140
<?php if ( (int) $site->network_id === (int) $network->id ) : ?>
141141

142-
<option value="<?php echo esc_attr( $site->id ); ?>" <?php disabled( is_main_site_for_network( $site->id ) ); ?>>
142+
<option value="<?php echo esc_attr( strval( $site->id ) ); ?>" <?php disabled( is_main_site_for_network( $site->id ) ); ?>>
143143
<?php echo esc_html( sprintf( '%1$s (%2$s%3$s)', $site->blogname, $site->domain, $site->path ) ); ?>
144144
</option>
145145

@@ -241,7 +241,7 @@ function wpmn_edit_network_publish_metabox( $network = null ) {
241241

242242
?>
243243
<input type="hidden" name="action" value="<?php echo esc_attr( $action ); ?>">
244-
<input type="hidden" name="network_id" value="<?php echo esc_attr( $network_id ); ?>">
244+
<input type="hidden" name="network_id" value="<?php echo esc_attr( strval( $network_id ) ); ?>">
245245
</div>
246246
<div class="clear"></div>
247247
</div>

wp-multi-network/includes/metaboxes/move-site.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function wpmn_move_site_assign_metabox( $site = null ) {
138138

139139
?>
140140
<input type="hidden" name="action" value="move">
141-
<input type="hidden" name="from" value="<?php echo esc_attr( $site->network_id ); ?>">
141+
<input type="hidden" name="from" value="<?php echo esc_attr( strval( $site->network_id ) ); ?>">
142142
</div>
143143
<div class="clear"></div>
144144
</div>

0 commit comments

Comments
 (0)