diff --git a/.github/workflows/phpstan-ci.yml b/.github/workflows/phpstan-ci.yml new file mode 100644 index 0000000..25727d5 --- /dev/null +++ b/.github/workflows/phpstan-ci.yml @@ -0,0 +1,23 @@ +name: Run PHPStan + +on: [push] + +jobs: + run-phpstan: + name: Static Analysis + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 'latest' + coverage: none + tools: composer, cs2pr + - name: Install PHP dependencies + uses: ramsey/composer-install@v2 + with: + composer-options: '--prefer-dist --no-scripts' + - name: PHPStan + run: composer phpstan diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 03046b9..e9a6fff 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,8 +6,8 @@ jobs: strategy: matrix: include: - - php: '5.6' - wordpress: '4.7' + - php: '7.2' + wordpress: '5.1' - php: '7.4' wordpress: '5.9' - php: '8.0' @@ -16,7 +16,7 @@ jobs: wordpress: '6.4' - php: '8.3' wordpress: 'latest' - - php: '8.3' + - php: '8.4' wordpress: 'nightly' steps: - name: Checkout diff --git a/composer.json b/composer.json index b45b614..dcb5c11 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "forum": "https://wordpress.org/support/plugin/cachify" }, "require": { - "php": ">=5.6", + "php": ">=7.2", "composer/installers": "^v1|^v2" }, "require-dev": { @@ -32,7 +32,11 @@ "squizlabs/php_codesniffer": "^3.10", "phpcompatibility/phpcompatibility-wp": "^2.1", "wp-coding-standards/wpcs": "^3.1", - "yoast/phpunit-polyfills": "^2.0" + "yoast/phpunit-polyfills": "^2.0", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^1.12", + "szepeviktor/phpstan-wordpress": "^1.0", + "php-stubs/wp-cli-stubs": "^2.11" }, "scripts": { "post-install-cmd": [ @@ -71,12 +75,16 @@ ], "coverage": [ "php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-html tests/coverage" + ], + "phpstan": [ + "vendor/bin/phpstan analyse --memory-limit=1G" ] }, "config": { "allow-plugins": { "dealerdirect/phpcodesniffer-composer-installer": true, - "composer/installers": true + "composer/installers": true, + "phpstan/extension-installer": true } } } diff --git a/inc/class-cachify.php b/inc/class-cachify.php index debe51c..41773b7 100644 --- a/inc/class-cachify.php +++ b/inc/class-cachify.php @@ -1073,8 +1073,8 @@ public static function register_publish_hooks() { /** * Removes the post type cache on post updates * - * @param int $post_id Post ID. - * @param object $post Post object. + * @param int $post_id Post ID. + * @param ?object $post Post object. * * @since 2.0.3 * diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..ca8b085 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,15 @@ +parameters: + level: 1 + paths: + - inc/ + - cachify.php + scanFiles: + - %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-stubs.php + - %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-commands-stubs.php + #- %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-i18n-stubs.php + #- %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-tools-stubs.php + excludePaths: + - inc/cachify.settings.php + ignoreErrors: + - '/^Constant CACHIFY_BASE not found\.$/' + - '/^Constant DOMAIN_CURRENT_SITE not found\.$/'