diff --git a/.github/workflows/phpcs.yml b/.github/workflows/phpcs.yml new file mode 100644 index 0000000..2146b72 --- /dev/null +++ b/.github/workflows/phpcs.yml @@ -0,0 +1,33 @@ +name: PHPCS check +on: + push + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + phpcs: + name: PHPCS check + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: "shivammathur/setup-php@v2" + with: + php-version: "7.4" + ini-values: "memory_limit=1G" + coverage: none + tools: cs2pr + + - name: Install Composer dependencies + uses: "ramsey/composer-install@v2" + + - name: Run PHPCS checks + continue-on-error: true + run: vendor/bin/phpcs --report-full --report-checkstyle=./phpcs-report.xml + + - name: Show PHPCS results in PR + run: cs2pr ./phpcs-report.xml diff --git a/README.md b/README.md index cd3af39..9ad9ebb 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![PHPCS](https://github.com/woocommerce/wc-smooth-generator/actions/workflows/phpcs.yml/badge.svg)](https://github.com/woocommerce/wc-smooth-generator/actions/workflows/phpcs.yml) + # WooCommerce Smooth Generator A smooth products, customer and order generator using WP-CLI. Future versions will include scheduled auto generation functionality. diff --git a/changelog.txt b/changelog.txt index 953215b..3b932ba 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,7 @@ 2022-06-30 - version 1.0.5 * Fix - Lower version requirement from PHP 8.0.2 to PHP 7.1. +* Dev - Run PHPCS checks in CI. 2021-12-15 - version 1.0.4 * Add - coupon generator and a new option for orders to allow for coupon generation. diff --git a/includes/Admin/Settings.php b/includes/Admin/Settings.php index 5e356f2..119f1dc 100644 --- a/includes/Admin/Settings.php +++ b/includes/Admin/Settings.php @@ -70,12 +70,12 @@ public static function process_page_submit() { $num_to_generate = absint( $_POST['num_products_to_generate'] ); wc_smooth_generate_schedule( 'product', $num_to_generate ); add_action( 'admin_notices', array( __CLASS__, 'product_generating_notice' ) ); - } else if ( ! empty( $_POST['generate_orders'] ) && ! empty( $_POST['num_orders_to_generate'] ) ) { + } elseif ( ! empty( $_POST['generate_orders'] ) && ! empty( $_POST['num_orders_to_generate'] ) ) { check_admin_referer( 'generate', 'smoothgenerator_nonce' ); $num_to_generate = absint( $_POST['num_orders_to_generate'] ); wc_smooth_generate_schedule( 'order', $num_to_generate ); add_action( 'admin_notices', array( __CLASS__, 'order_generating_notice' ) ); - } else if ( ! empty( $_POST['cancel_all_generations'] ) ) { + } elseif ( ! empty( $_POST['cancel_all_generations'] ) ) { check_admin_referer( 'generate', 'smoothgenerator_nonce' ); wc_smooth_generate_cancel_all(); } diff --git a/includes/Generator/Product.php b/includes/Generator/Product.php index 49e7538..d4e49d9 100644 --- a/includes/Generator/Product.php +++ b/includes/Generator/Product.php @@ -126,8 +126,8 @@ protected static function create_global_attribute( $raw_name ) { $taxonomy_name = wc_attribute_taxonomy_name( $slug ); register_taxonomy( $taxonomy_name, - apply_filters( 'woocommerce_taxonomy_objects_' . $taxonomy_name, array( 'product' ) ), - apply_filters( 'woocommerce_taxonomy_args_' . $taxonomy_name, array( + apply_filters( 'woocommerce_taxonomy_objects_' . $taxonomy_name, array( 'product' ) ), // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment + apply_filters( 'woocommerce_taxonomy_args_' . $taxonomy_name, array( // phpcs:ignore WooCommerce.Commenting.CommentHooks.MissingHookComment 'labels' => array( 'name' => $raw_name, ), diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 32309e0..0876dab 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -10,6 +10,7 @@ */vendor/* */node_modules/* + Gruntfile\.js