Skip to content

Commit c3e3b4a

Browse files
authored
Introduce PHPStan for Static Analysis (#213)
* Lowered level to 0 and fixed the errors * Github action for PHPStan * Name for PHPStan's job * PHPStan plugin installer + PHP Stubs for WP_CLI * PHPStan explicit install * Github workflow changed
1 parent 352df9a commit c3e3b4a

File tree

7 files changed

+56
-16
lines changed

7 files changed

+56
-16
lines changed

.github/workflows/phpstan-ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Run PHPStan
2+
3+
on: [push]
4+
5+
jobs:
6+
run-phpstan:
7+
name: Static Analysis
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v4
12+
- name: Setup PHP
13+
uses: shivammathur/setup-php@v2
14+
with:
15+
php-version: 'latest'
16+
coverage: none
17+
tools: composer, cs2pr
18+
- name: Install PHP dependencies
19+
uses: ramsey/composer-install@v2
20+
with:
21+
composer-options: '--prefer-dist --no-scripts'
22+
- name: PHPStan
23+
run: composer phpstan

composer.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,22 @@
2020
"composer/installers": "^1.0 || ^2.0"
2121
},
2222
"require-dev": {
23+
"php-stubs/wp-cli-stubs": "^2.11",
2324
"phpcompatibility/phpcompatibility-wp": "^2.1.0",
25+
"phpstan/extension-installer": "^1.4",
26+
"phpstan/phpstan": "^1.12",
27+
"szepeviktor/phpstan-wordpress": "^1.0",
2428
"wp-coding-standards/wpcs": "^3.1.0",
2529
"yoast/wp-test-utils": "^1.2"
2630
},
31+
"scripts": {
32+
"phpstan": "vendor/bin/phpstan analyse --memory-limit=1G"
33+
},
2734
"config": {
2835
"allow-plugins": {
2936
"composer/installers": true,
30-
"dealerdirect/phpcodesniffer-composer-installer": true
37+
"dealerdirect/phpcodesniffer-composer-installer": true,
38+
"phpstan/extension-installer": true
3139
},
3240
"sort-packages": true
3341
}

phpstan.neon.dist

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
parameters:
2+
level: 0
3+
paths:
4+
- wp-multi-network/includes
5+
- wpmn-loader.php
6+
scanFiles:
7+
- %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-stubs.php
8+
- %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-commands-stubs.php
9+
#- %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-i18n-stubs.php
10+
#- %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-tools-stubs.php
11+
ignoreErrors:
12+
- '/^Call to static method encode\(\) on an unknown class Requests_IDNAEncoder.$/'
13+

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* @since 1.3.0
1313
*/
14-
class WP_MS_Network_Command extends WP_CLI_Command {
14+
class WP_MS_Network_Command {
1515

1616
/**
1717
* Default fields to display for each object.
@@ -260,7 +260,7 @@ public function list_( $args, $assoc_args ) {
260260
* @param array $assoc_args Associative CLI arguments.
261261
*/
262262
public function plugin( $args, $assoc_args ) {
263-
$this->fetcher = new \WP_CLI\Fetchers\Plugin();
263+
$fetchers_plugin = new \WP_CLI\Fetchers\Plugin();
264264
$action = array_shift( $args );
265265
if ( ! in_array( $action, array( 'activate', 'deactivate' ), true ) ) {
266266
WP_CLI::error( sprintf( '%s is not a supported action.', $action ) );
@@ -284,7 +284,7 @@ function ( $file ) {
284284
}, array_keys( get_plugins() )
285285
);
286286
}
287-
foreach ( $this->fetcher->get_many( $args ) as $plugin ) {
287+
foreach ( $fetchers_plugin->get_many( $args ) as $plugin ) {
288288
$status = $this->get_status( $plugin->file );
289289
if ( $all && in_array( $status, array( 'active', 'active-network' ), true ) ) {
290290
--$needing_activation;

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
@@ -479,9 +479,9 @@ protected function handle_row_actions( $network, $column_name, $primary ) {
479479
*
480480
* @since 2.0.0
481481
*
482-
* @param array Action links as $slug => $link_markup pairs.
483-
* @param int The current network ID.
484-
* @param string The current network name.
482+
* @param array $filtered_acions Action links as $slug => $link_markup pairs.
483+
* @param int $network_id The current network ID.
484+
* @param string $network_sitename The current network name.
485485
*/
486486
$actions = apply_filters( 'manage_networks_action_links', array_filter( $actions ), $network->id, $network->sitename );
487487

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,6 @@ public function update_item( $request ) {
449449
}
450450

451451
if ( ! empty( $prepared_args ) ) {
452-
if ( is_wp_error( $prepared_args ) ) {
453-
return $prepared_args;
454-
}
455-
456452
$domain = $prepared_args['domain'];
457453
$path = $prepared_args['path'];
458454

wp-multi-network/includes/functions.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ function user_has_networks( $user_id = 0 ) {
7474
*
7575
* @since 2.0.0
7676
*
77-
* @param array|bool|null List of network IDs or false. Anything but null will short-circuit
78-
* the process.
79-
* @param int User ID for which the networks should be returned.
77+
* @param array|bool|null $my_networks List of network IDs or false. Anything but null will short-circuit
78+
* the process.
79+
* @param int $user_id User ID for which the networks should be returned.
8080
*/
8181
$my_networks = apply_filters( 'networks_pre_user_is_network_admin', null, $user_id );
8282
if ( null !== $my_networks ) {
@@ -89,8 +89,8 @@ function user_has_networks( $user_id = 0 ) {
8989
*
9090
* @since 2.0.0
9191
*
92-
* @param array|bool List of network IDs or false if no networks for the user.
93-
* @param int User ID for which the networks should be returned.
92+
* @param array|bool $my_networks List of network IDs or false if no networks for the user.
93+
* @param int $user_id User ID for which the networks should be returned.
9494
*/
9595
return apply_filters( 'networks_user_is_network_admin', $my_networks, $user_id );
9696
}

0 commit comments

Comments
 (0)