Skip to content

Commit

Permalink
Merge pull request #638 from WordPress/618-add-phpstan
Browse files Browse the repository at this point in the history
Add basic PHPStan linter
  • Loading branch information
kasparsd authored Sep 19, 2024
2 parents acd9e9c + 47425c5 commit 3f41808
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 4 deletions.
3 changes: 2 additions & 1 deletion .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
/package-lock.json
/phpcs*
/phpunit*
/phpstan.*
/readme.md
/SECURITY.md
/SECURITY.md
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ jobs:
- name: Lint PHP Compatibility
run: composer lint-compat

- name: PHPStan
run: npm run lint:phpstan

test-php:
name: Test PHP ${{ matrix.php }} ${{ matrix.wp != '' && format( ' (WP {0}) ', matrix.wp ) || '' }}
runs-on: ubuntu-latest
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/dist/
/tests/logs/
.phpunit.result.cache
phpstan.neon
2 changes: 1 addition & 1 deletion class-two-factor-compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ public function jetpack_rememberme( $rememberme ) {
* @return boolean
*/
public function jetpack_is_sso_active() {
return ( method_exists( 'Jetpack', 'is_module_active' ) && Jetpack::is_module_active( 'sso' ) );
return ( class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'is_module_active' ) && Jetpack::is_module_active( 'sso' ) );
}
}
2 changes: 1 addition & 1 deletion class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class Two_Factor_Core {
* @since 0.1-dev
*/
public static function add_hooks( $compat ) {
add_action( 'init', array( __CLASS__, 'get_providers' ) );
add_action( 'init', array( __CLASS__, 'get_providers' ) ); // @phpstan-ignore return.void
add_action( 'wp_login', array( __CLASS__, 'wp_login' ), 10, 2 );
add_filter( 'wp_login_errors', array( __CLASS__, 'maybe_show_reset_password_notice' ) );
add_action( 'after_password_reset', array( __CLASS__, 'clear_password_reset_notice' ) );
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
"phpcompatibility/phpcompatibility-wp": "^2.1",
"phpunit/phpunit": "^8.5|^9.6",
"spatie/phpunit-watcher": "^1.23",
"szepeviktor/phpstan-wordpress": "^1.3",
"wp-coding-standards/wpcs": "^3.1",
"yoast/phpunit-polyfills": "^2.0"
},
"scripts": {
"lint": "phpcs",
"lint-compat": "phpcs -p --standard=PHPCompatibilityWP --runtime-set testVersion 7.2- --extensions=php --ignore='tests/,dist/,includes/Yubico/,vendor/,node_modules/' .",
"lint-phpstan": "phpstan analyse --verbose --memory-limit=1G",
"test": "vendor/bin/phpunit",
"test:watch": [
"Composer\\Config::disableProcessTimeout",
Expand Down
171 changes: 170 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"build": "grunt build",
"lint": "npm-run-all lint:*",
"lint:php": "composer lint",
"lint:phpstan": "composer lint-phpstan",
"lint:css": "wp-scripts lint-style ./user-edit.css ./providers/css/",
"lint:js": "wp-scripts lint-js ./Gruntfile.js ./providers/js/",
"format": "npm-run-all format:*",
Expand Down
10 changes: 10 additions & 0 deletions phpstan.dist.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
includes:
- vendor/szepeviktor/phpstan-wordpress/extension.neon
parameters:
level: 0
paths:
- includes
- providers
- class-two-factor-compat.php
- class-two-factor-core.php
- two-factor.php

0 comments on commit 3f41808

Please sign in to comment.