Skip to content

Commit 542d9c1

Browse files
authored
PHPStan Level 6 (#221)
* PHPStan Level 6 * esc_html_e does not need echo * @return void for the first batch of functions * @return void for the second batch of functions * @return void for commands, throw error transformed into WP_CLI::error() * Value type specified in iterable type array * Solves 'Method x has parameter y with generic class z but does not specify its types: T'
1 parent 240ab1b commit 542d9c1

12 files changed

+132
-64
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: 5
2+
level: 6
33
paths:
44
- wp-multi-network/includes
55
- wpmn-loader.php

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

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class WP_MS_Network_Command {
1717
* Default fields to display for each object.
1818
*
1919
* @since 1.3.0
20-
* @var array
20+
* @var string[]
2121
*/
2222
protected $obj_fields = array(
2323
'id',
@@ -54,11 +54,12 @@ class WP_MS_Network_Command {
5454
*
5555
* @since 1.3.0
5656
*
57-
* @param array $args Positional CLI arguments.
58-
* @param array $assoc_args Associative CLI arguments.
57+
* @param string[] $args Positional CLI arguments.
58+
* @param array<string, mixed> $assoc_args Associative CLI arguments.
59+
* @return void
5960
*/
6061
public function create( $args, $assoc_args ) {
61-
list( $domain, $path ) = $args;
62+
[ $domain, $path ] = $args;
6263

6364
$assoc_args = wp_parse_args(
6465
$assoc_args, array(
@@ -74,7 +75,7 @@ public function create( $args, $assoc_args ) {
7475
$users = new \WP_CLI\Fetchers\User();
7576
$user = $users->get( $assoc_args['network_admin'] );
7677
if ( ! $user ) {
77-
return new WP_Error( 'network_super_admin', 'Super user does not exist.' );
78+
WP_CLI::error( 'Super user does not exist.' );
7879
}
7980
$network_admin_id = $user->ID;
8081
} else {
@@ -122,18 +123,19 @@ public function create( $args, $assoc_args ) {
122123
*
123124
* @since 1.3.0
124125
*
125-
* @param array $args Positional CLI arguments.
126-
* @param array $assoc_args Associative CLI arguments.
126+
* @param string[] $args Positional CLI arguments.
127+
* @param array<string, mixed> $assoc_args Associative CLI arguments.
128+
* @return void
127129
*/
128130
public function update( $args, $assoc_args ) {
129-
list( $id, $domain ) = $args;
131+
[ $id, $domain ] = $args;
130132

131133
$defaults = array(
132134
'path' => '',
133135
);
134136
$assoc_args = wp_parse_args( $assoc_args, $defaults );
135137

136-
$network_id = update_network( $id, $domain, $assoc_args['path'] );
138+
$network_id = update_network( (int) $id, $domain, $assoc_args['path'] );
137139

138140
if ( is_wp_error( $network_id ) ) {
139141
WP_CLI::error( $network_id );
@@ -153,19 +155,20 @@ public function update( $args, $assoc_args ) {
153155
*
154156
* @since 1.3.0
155157
*
156-
* @param array $args Positional CLI arguments.
157-
* @param array $assoc_args Associative CLI arguments.
158+
* @param string[] $args Positional CLI arguments.
159+
* @param array<string, mixed> $assoc_args Associative CLI arguments.
160+
* @return void
158161
*/
159162
public function delete( $args, $assoc_args ) {
160-
list( $id ) = $args;
163+
[ $id ] = $args;
161164

162165
$assoc_args = wp_parse_args(
163166
$assoc_args, array(
164167
'delete_blogs' => false,
165168
)
166169
);
167170

168-
$network_id = delete_network( $id, $assoc_args['delete_blogs'] );
171+
$network_id = delete_network( (int) $id, $assoc_args['delete_blogs'] );
169172

170173
if ( is_wp_error( $network_id ) ) {
171174
WP_CLI::error( $network_id );
@@ -187,13 +190,14 @@ public function delete( $args, $assoc_args ) {
187190
*
188191
* @since 1.3.0
189192
*
190-
* @param array $args Positional CLI arguments.
191-
* @param array $assoc_args Associative CLI arguments.
193+
* @param string[] $args Positional CLI arguments.
194+
* @param array<string, mixed> $assoc_args Associative CLI arguments.
195+
* @return void
192196
*/
193197
public function move_site( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
194-
list( $site_id, $new_network_id ) = $args;
198+
[ $site_id, $new_network_id ] = $args;
195199

196-
$network_id = move_site( $site_id, $new_network_id );
200+
$network_id = move_site( (int) $site_id, (int) $new_network_id );
197201

198202
if ( is_wp_error( $network_id ) ) {
199203
WP_CLI::error( $network_id );
@@ -223,8 +227,9 @@ public function move_site( $args, $assoc_args ) { // phpcs:ignore Generic.CodeAn
223227
*
224228
* @since 1.3.0
225229
*
226-
* @param array $args Positional CLI arguments.
227-
* @param array $assoc_args Associative CLI arguments.
230+
* @param string[] $args Positional CLI arguments.
231+
* @param array<string, mixed> $assoc_args Associative CLI arguments.
232+
* @return void
228233
*/
229234
public function list_( $args, $assoc_args ) {
230235
$items = get_networks();
@@ -252,8 +257,9 @@ public function list_( $args, $assoc_args ) {
252257
*
253258
* @since 1.3.0
254259
*
255-
* @param array $args Positional CLI arguments.
256-
* @param array $assoc_args Associative CLI arguments.
260+
* @param string[] $args Positional CLI arguments.
261+
* @param array<string, mixed> $assoc_args Associative CLI arguments.
262+
* @return void
257263
*/
258264
public function plugin( $args, $assoc_args ) {
259265
$fetchers_plugin = new \WP_CLI\Fetchers\Plugin();
@@ -276,7 +282,7 @@ public function plugin( $args, $assoc_args ) {
276282
if ( $all ) {
277283
$args = array_map(
278284
function ( $file ) {
279-
return \WP_CLI\Utils\get_plugin_name( $file );
285+
return \WP_CLI\Utils\get_plugin_name( $file );
280286
}, array_keys( get_plugins() )
281287
);
282288
}
@@ -322,7 +328,7 @@ function ( $file ) {
322328
*
323329
* @since 1.3.0
324330
*
325-
* @param array $assoc_args Associative CLI arguments. Passed by reference.
331+
* @param array<string, mixed> $assoc_args Associative CLI arguments. Passed by reference.
326332
* @return WP_CLI\Formatter WP-CLI formatter instance.
327333
*/
328334
protected function get_formatter( &$assoc_args ) {
@@ -373,6 +379,7 @@ protected function get_status( $file ) {
373379
* @param string $file Plugin main file path relative to the plugins directory.
374380
* @param bool $network_wide Whether to check network-wide or not.
375381
* @param string $action Action performed.
382+
* @return void
376383
*/
377384
private function active_output( $name, $file, $network_wide, $action ) {
378385
$network_wide = $network_wide || ( is_multisite() && is_network_only_plugin( $file ) );

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function add_hooks(): void {
4040
*
4141
* @since 2.2.0
4242
* @since 3.0.0 Prevent rendering of CSS if admin bar is not shown.
43+
* @return void
4344
*/
4445
public function admin_print_styles() {
4546
if ( ! is_admin_bar_showing() ) {
@@ -61,6 +62,7 @@ public function admin_print_styles() {
6162
* @since 2.2.0
6263
*
6364
* @param WP_Admin_Bar $wp_admin_bar Admin bar instance.
65+
* @return void
6466
*/
6567
public function admin_bar( $wp_admin_bar ) {
6668

0 commit comments

Comments
 (0)