Skip to content

Commit

Permalink
Merge pull request #931 from carstingaxion/try/phpstan-for-wp
Browse files Browse the repository at this point in the history
NEW action PHPStan & 36 little 🐛 fixes
  • Loading branch information
mauteri authored Oct 4, 2024
2 parents 4169145 + c615cd5 commit 5d4b241
Show file tree
Hide file tree
Showing 28 changed files with 479 additions and 68 deletions.
3 changes: 3 additions & 0 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ package-lock.json
phpcs.xml
phpcs.xml.dist
phpcs.ruleset.xml
phpstan.neon
phpstan.neon.dist
phpstan.stubs
phpunit.xml
phpunit.xml.dist
playwright.config.js
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/phpstan-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: PHPStan Tests
on:
push:
branches:
- main
pull_request:
paths:
- '.github/workflows/phpstan-tests.yml'
- 'includes/**'
# - 'test/unit/php**'
# - '*.php'
- 'phpstan.neon.dist'
- 'composer.*'
jobs:
test-phpstan:
name: PHPStan for WordPress
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
# phpstan requires PHP 7.1+.
php-version: 7.4
extensions: dom, iconv, json, libxml, zip
coverage: none
tools: cs2pr

- name: Composer Install
run: composer install --optimize-autoloader --prefer-dist

- name: Log debug information
run: |
git --version
php --version
composer --version
- name: Running PHPStan Analyze
if: ${{ success() || failure() }}
run: |
vendor/bin/phpstan --version
vendor/bin/phpstan analyze -vv --memory-limit=2G --error-format=checkstyle | cs2pr
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ typings
# Composer #
##########
vendor
phpstan.neon

# .wp-env #
##########
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"wp-coding-standards/wpcs": "*",
"phpcompatibility/phpcompatibility-wp": "*",
"phpunit/phpunit": "*",
"yoast/phpunit-polyfills": "*"
"yoast/phpunit-polyfills": "*",
"szepeviktor/phpstan-wordpress": "^1.3"
},
"suggest": {
"wp-cli/wp-cli-bundle": "Combines the most common WP-CLI commands, including the wp-cli/i18n-command which should be used to create translation-files."
Expand All @@ -28,7 +29,8 @@
"format": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf --report=summary,source",
"lint": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --report=summary,source",
"lint:errors": "@lint -n",
"test": "@php ./vendor/phpunit/phpunit/phpunit"
"test": "@php ./vendor/phpunit/phpunit/phpunit",
"test:phpstan": "@php ./vendor/bin/phpstan analyze -vv --memory-limit=2G"
},
"config": {
"allow-plugins": {
Expand Down
247 changes: 246 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 gatherpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore

// Constants.
define( 'GATHERPRESS_CACHE_GROUP', 'gatherpress_cache' );
define( 'GATHERPRESS_CORE_FILE', __FILE__ );
define( 'GATHERPRESS_CORE_PATH', __DIR__ );
define( 'GATHERPRESS_CORE_URL', plugin_dir_url( __FILE__ ) );
Expand Down
3 changes: 1 addition & 2 deletions includes/core/classes/class-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected function setup_hooks(): void {
*/
public function add_global_object(): void {
?>
<script>window.GatherPress = <?php echo wp_json_encode( $this->localize( get_the_ID() ?? 0 ) ); ?></script>
<script>window.GatherPress = <?php echo wp_json_encode( $this->localize( intval( get_the_ID() ) ) ); ?></script>
<?php
}

Expand Down Expand Up @@ -385,7 +385,6 @@ protected function unregister_blocks(): array {

switch ( get_post_type() ) {
case Event::POST_TYPE:
$blocks;
break;
case Venue::POST_TYPE:
$blocks = array(
Expand Down
Loading

0 comments on commit 5d4b241

Please sign in to comment.