diff --git a/.editorconfig b/.editorconfig index fa483b1..84f918e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,6 +4,8 @@ # WordPress Coding Standards # https://make.wordpress.org/core/handbook/coding-standards/ +# From https://github.com/WordPress/wordpress-develop/blob/trunk/.editorconfig with a couple of additions. + root = true [*] @@ -13,13 +15,12 @@ insert_final_newline = true trim_trailing_whitespace = true indent_style = tab -[{.jshintrc,*.json,*.yml,*.feature}] +[{*.yml,*.feature,.jshintrc,*.json}] indent_style = space indent_size = 2 +[*.md] +trim_trailing_whitespace = false + [{*.txt,wp-config-sample.php}] end_of_line = crlf - -[composer.json] -indent_style = space -indent_size = 4 diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b60e661..d6c7b8b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -7,3 +7,11 @@ updates: open-pull-requests-limit: 10 labels: - scope:distribution + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily + open-pull-requests-limit: 10 + labels: + - scope:distribution + diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 54c324a..07e4fd1 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -7,87 +7,6 @@ on: - main - master -# Cancels all previous workflow runs for the same branch that have not yet completed. -concurrency: - # The concurrency group contains the workflow name and the branch name. - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - jobs: - - lint: #----------------------------------------------------------------------- - name: Lint PHP files - runs-on: ubuntu-latest - steps: - - name: Check out source code - uses: actions/checkout@v2 - - - name: Check existence of composer.json file - id: check_composer_file - uses: andstor/file-existence-action@v1 - with: - files: "composer.json" - - - name: Set up PHP environment - if: steps.check_composer_file.outputs.files_exists == 'true' - uses: shivammathur/setup-php@v2 - with: - php-version: '7.4' - tools: cs2pr - env: - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Install Composer dependencies & cache dependencies - if: steps.check_composer_file.outputs.files_exists == 'true' - uses: "ramsey/composer-install@v2" - env: - COMPOSER_ROOT_VERSION: 'dev-main' - - - name: Check existence of vendor/bin/parallel-lint file - id: check_linter_file - uses: andstor/file-existence-action@v1 - with: - files: "vendor/bin/parallel-lint" - - - name: Run Linter - if: steps.check_linter_file.outputs.files_exists == 'true' - run: vendor/bin/parallel-lint -j 10 . --exclude vendor --checkstyle | cs2pr - - phpcs: #---------------------------------------------------------------------- - name: PHPCS - runs-on: ubuntu-latest - - steps: - - name: Check out source code - uses: actions/checkout@v2 - - - name: Check existence of composer.json & phpcs.xml.dist files - id: check_files - uses: andstor/file-existence-action@v1 - with: - files: "composer.json, phpcs.xml.dist" - - - name: Set up PHP environment - if: steps.check_files.outputs.files_exists == 'true' - uses: shivammathur/setup-php@v2 - with: - php-version: '7.4' - tools: cs2pr - env: - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Install Composer dependencies & cache dependencies - if: steps.check_files.outputs.files_exists == 'true' - uses: "ramsey/composer-install@v2" - env: - COMPOSER_ROOT_VERSION: 'dev-main' - - - name: Check existence of vendor/bin/phpcs file - id: check_phpcs_binary_file - uses: andstor/file-existence-action@v1 - with: - files: "vendor/bin/phpcs" - - - name: Run PHPCS - if: steps.check_phpcs_binary_file.outputs.files_exists == 'true' - run: vendor/bin/phpcs -q --report=checkstyle | cs2pr + code-quality: + uses: wp-cli/.github/.github/workflows/reusable-code-quality.yml@main diff --git a/.github/workflows/regenerate-readme.yml b/.github/workflows/regenerate-readme.yml index 9469b04..c633d9d 100644 --- a/.github/workflows/regenerate-readme.yml +++ b/.github/workflows/regenerate-readme.yml @@ -7,98 +7,9 @@ on: - main - master paths-ignore: - - 'features/**' - - 'README.md' - -# Cancels all previous workflow runs for the same branch that have not yet completed. -concurrency: - # The concurrency group contains the workflow name and the branch name. - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - + - "features/**" + - "README.md" jobs: - - regenerate-readme: #---------------------------------------------------------- - name: Regenerate README.md file - runs-on: ubuntu-latest - if: ${{ github.repository_owner == 'wp-cli' && ! contains(fromJson('[".github", "wp-cli", "wp-cli-bundle", "wp-super-cache-cli", "php-cli-tools", "wp-config-transformer"]'), github.event.repository.name) }} - steps: - - name: Check out source code - uses: actions/checkout@v2 - - - name: Set up PHP envirnoment - uses: shivammathur/setup-php@v2 - with: - php-version: '7.4' - env: - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Check existence of composer.json file - id: check_composer_file - uses: andstor/file-existence-action@v1 - with: - files: "composer.json" - - - name: Install Composer dependencies & cache dependencies - if: steps.check_composer_file.outputs.files_exists == 'true' - uses: "ramsey/composer-install@v2" - env: - COMPOSER_ROOT_VERSION: 'dev-main' - - - name: Configure git user - run: | - git config --global user.email "alain.schlesser@gmail.com" - git config --global user.name "Alain Schlesser" - - - name: Check if remote branch exists - id: remote-branch - run: echo ::set-output name=exists::$([[ -z $(git ls-remote --heads origin regenerate-readme) ]] && echo "0" || echo "1") - - - name: Create branch to base pull request on - if: steps.remote-branch.outputs.exists == 0 - run: | - git checkout -b regenerate-readme - - - name: Fetch existing branch to add commits to - if: steps.remote-branch.outputs.exists == 1 - run: | - git fetch --all --prune - git checkout regenerate-readme - git pull --no-rebase - - - name: Install WP-CLI - run: | - curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli-nightly.phar - sudo mv wp-cli-nightly.phar /usr/local/bin/wp - sudo chmod +x /usr/local/bin/wp - - - name: Regenerate README.md file - run: | - wp package install "wp-cli/scaffold-package-command:^2" - wp scaffold package-readme --force . - - - name: Check if there are changes - id: changes - run: echo ::set-output name=changed::$([[ -z $(git status --porcelain) ]] && echo "0" || echo "1") - - - name: Commit changes - if: steps.changes.outputs.changed == 1 - run: | - git add README.md - git commit -m "Regenerate README file - $(date +'%Y-%m-%d')" - git push origin regenerate-readme - - - name: Create pull request - if: | - steps.changes.outputs.changed == 1 && - steps.remote-branch.outputs.exists == 0 - uses: repo-sync/pull-request@v2 - with: - source_branch: regenerate-readme - destination_branch: main - github_token: ${{ secrets.GITHUB_TOKEN }} - pr_title: Regenerate README file - pr_body: "**This is an automated pull-request**\n\nRefreshes the `README.md` file with the latest changes to the docblocks in the source code." - pr_reviewer: schlessera - pr_label: scope:documentation + regenerate-readme: + uses: wp-cli/.github/.github/workflows/reusable-regenerate-readme.yml@main diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index f7f80da..1044b79 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -6,166 +6,9 @@ on: branches: - main - master - -# Cancels all previous workflow runs for the same branch that have not yet completed. -concurrency: - # The concurrency group contains the workflow name and the branch name. - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true + schedule: + - cron: '17 1 * * *' # Run every day on a seemly random time. jobs: - - unit: #----------------------------------------------------------------------- - name: Unit test / PHP ${{ matrix.php }} - strategy: - fail-fast: false - matrix: - php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] - runs-on: ubuntu-20.04 - - steps: - - name: Check out source code - uses: actions/checkout@v2 - - - name: Check existence of composer.json file - id: check_files - uses: andstor/file-existence-action@v1 - with: - files: "composer.json, phpunit.xml.dist" - - - name: Set up PHP environment - if: steps.check_files.outputs.files_exists == 'true' - uses: shivammathur/setup-php@v2 - with: - php-version: '${{ matrix.php }}' - coverage: none - tools: composer,cs2pr - env: - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Install Composer dependencies & cache dependencies - if: steps.check_files.outputs.files_exists == 'true' - uses: "ramsey/composer-install@v2" - env: - COMPOSER_ROOT_VERSION: 'dev-main' - - - name: Setup problem matcher to provide annotations for PHPUnit - if: steps.check_files.outputs.files_exists == 'true' - run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - - name: Run PHPUnit - if: steps.check_files.outputs.files_exists == 'true' - run: composer phpunit - - functional: #---------------------------------------------------------------------- - name: Functional - WP ${{ matrix.wp }} on PHP ${{ matrix.php }} with MySQL ${{ matrix.mysql }} - strategy: - fail-fast: false - matrix: - php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] - wp: ['latest'] - mysql: ['8.0'] - include: - - php: '5.6' - wp: 'trunk' - mysql: '8.0' - - php: '5.6' - wp: 'trunk' - mysql: '5.7' - - php: '5.6' - wp: 'trunk' - mysql: '5.6' - - php: '7.4' - wp: 'trunk' - mysql: '8.0' - - php: '8.0' - wp: 'trunk' - mysql: '8.0' - - php: '8.0' - wp: 'trunk' - mysql: '5.7' - - php: '8.0' - wp: 'trunk' - mysql: '5.6' - - php: '8.1' - wp: 'trunk' - mysql: '8.0' - - php: '5.6' - wp: '3.7' - mysql: '5.6' - runs-on: ubuntu-20.04 - - services: - mysql: - image: mysql:${{ matrix.mysql }} - ports: - - 3306 - options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=wp_cli_test --entrypoint sh mysql:${{ matrix.mysql }} -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password" - - steps: - - name: Check out source code - uses: actions/checkout@v2 - - - name: Check existence of composer.json & behat.yml files - id: check_files - uses: andstor/file-existence-action@v1 - with: - files: "composer.json, behat.yml" - - - name: Install Ghostscript - if: steps.check_files.outputs.files_exists == 'true' - run: | - sudo apt-get update - sudo apt-get install ghostscript -y - - - name: Set up PHP envirnoment - if: steps.check_files.outputs.files_exists == 'true' - uses: shivammathur/setup-php@v2 - with: - php-version: '${{ matrix.php }}' - extensions: gd, imagick, mysql, zip - coverage: none - tools: composer - env: - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Change ImageMagick policy to allow pdf->png conversion. - if: steps.check_files.outputs.files_exists == 'true' - run: | - sudo sed -i 's/^.*policy.*coder.*none.*PDF.*//' /etc/ImageMagick-6/policy.xml - - - name: Install Composer dependencies & cache dependencies - if: steps.check_files.outputs.files_exists == 'true' - uses: "ramsey/composer-install@v2" - env: - COMPOSER_ROOT_VERSION: 'dev-main' - - - name: Start MySQL server - if: steps.check_files.outputs.files_exists == 'true' - run: sudo systemctl start mysql - - - name: Configure DB environment - if: steps.check_files.outputs.files_exists == 'true' - run: | - echo "MYSQL_HOST=127.0.0.1" >> $GITHUB_ENV - echo "MYSQL_TCP_PORT=${{ job.services.mysql.ports['3306'] }}" >> $GITHUB_ENV - echo "WP_CLI_TEST_DBROOTUSER=root" >> $GITHUB_ENV - echo "WP_CLI_TEST_DBROOTPASS=root" >> $GITHUB_ENV - echo "WP_CLI_TEST_DBNAME=wp_cli_test" >> $GITHUB_ENV - echo "WP_CLI_TEST_DBUSER=wp_cli_test" >> $GITHUB_ENV - echo "WP_CLI_TEST_DBPASS=password1" >> $GITHUB_ENV - echo "WP_CLI_TEST_DBHOST=127.0.0.1:${{ job.services.mysql.ports['3306'] }}" >> $GITHUB_ENV - - - name: Prepare test database - if: steps.check_files.outputs.files_exists == 'true' - run: composer prepare-tests - - - name: Check Behat environment - if: steps.check_files.outputs.files_exists == 'true' - run: WP_CLI_TEST_DEBUG_BEHAT_ENV=1 composer behat - - - name: Run Behat - if: steps.check_files.outputs.files_exists == 'true' - env: - WP_VERSION: '${{ matrix.wp }}' - run: composer behat || composer behat-rerun + test: + uses: wp-cli/.github/.github/workflows/reusable-testing.yml@main diff --git a/README.md b/README.md index dd0eecd..5785f84 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Quick links: [Overview](#overview) | [Using](#using) | [Installing](#installing) `wp doctor` lets you easily run a series of configurable checks to diagnose what's ailing with WordPress. -Without `wp doctor`, your team has to rely on their memory to manually debug problems. With `wp doctor`, your team saves hours identifying the health of your WordPress installs by codifying diagnosis procedures as a series of checks to run with WP-CLI. `wp doctor` [comes with dozens of checks out of the box](https://runcommand.io/to/doctor-default-checks/), and [supports customized `doctor.yml` files](https://runcommand.io/to/customize-doctor-config/) to define the checks that are most important to you. +Without `wp doctor`, your team has to rely on their memory to manually debug problems. With `wp doctor`, your team saves hours identifying the health of your WordPress installs by codifying diagnosis procedures as a series of checks to run with WP-CLI. `wp doctor` [comes with dozens of checks out of the box](https://make.wordpress.org/cli/handbook/guides/doctor/doctor-default-checks/), and [supports customized `doctor.yml` files](https://make.wordpress.org/cli/handbook/guides/doctor/doctor-customize-config/) to define the checks that are most important to you. Each check includes a name, status (either "success", "warning", or "error"), and a human-readable message. For example, `cron-count` is a check to ensure WP Cron hasn't exploded with jobs: diff --git a/bin/readme/overview-body.md b/bin/readme/overview-body.md index ca77124..081f749 100644 --- a/bin/readme/overview-body.md +++ b/bin/readme/overview-body.md @@ -1,6 +1,6 @@ `wp doctor` lets you easily run a series of configurable checks to diagnose what's ailing with WordPress. -Without `wp doctor`, your team has to rely on their memory to manually debug problems. With `wp doctor`, your team saves hours identifying the health of your WordPress installs by codifying diagnosis procedures as a series of checks to run with WP-CLI. `wp doctor` [comes with dozens of checks out of the box](https://runcommand.io/to/doctor-default-checks/), and [supports customized `doctor.yml` files](https://runcommand.io/to/customize-doctor-config/) to define the checks that are most important to you. +Without `wp doctor`, your team has to rely on their memory to manually debug problems. With `wp doctor`, your team saves hours identifying the health of your WordPress installs by codifying diagnosis procedures as a series of checks to run with WP-CLI. `wp doctor` [comes with dozens of checks out of the box](https://make.wordpress.org/cli/handbook/guides/doctor/doctor-default-checks/), and [supports customized `doctor.yml` files](https://make.wordpress.org/cli/handbook/guides/doctor/doctor-customize-config/) to define the checks that are most important to you. Each check includes a name, status (either "success", "warning", or "error"), and a human-readable message. For example, `cron-count` is a check to ensure WP Cron hasn't exploded with jobs: diff --git a/composer.json b/composer.json index 9d8614b..4be66fa 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "wp-cli/wp-cli": "^2.1" }, "require-dev": { - "wp-cli/wp-cli-tests": "^3.1.4" + "wp-cli/wp-cli-tests": "^4" }, "config": { "process-timeout": 7200, @@ -66,6 +66,7 @@ "behat-rerun": "rerun-behat-tests", "lint": "run-linter-tests", "phpcs": "run-phpcs-tests", + "phpcbf": "run-phpcbf-cleanup", "phpunit": "run-php-unit-tests", "prepare-tests": "install-package-tests", "test": [ diff --git a/features/check-plugin-active-count.feature b/features/check-plugin-active-count.feature index 48c9f4b..fd040b4 100644 --- a/features/check-plugin-active-count.feature +++ b/features/check-plugin-active-count.feature @@ -33,3 +33,12 @@ Feature: Check whether a high number of plugins are activated Then STDOUT should be a table containing rows: | name | status | message | | plugin-active-count | warning | Number of active plugins (4) exceeds threshold (3). | + + Scenario: Include network-enabled plugins in active plugin count + Given a WP multisite installation + And I run `wp plugin activate --network --all` + + When I run `wp doctor check plugin-active-count` + Then STDOUT should be a table containing rows: + | name | status | message | + | plugin-active-count | success | Number of active plugins (2) is less than threshold (80). | diff --git a/features/check-plugin-deactivated.feature b/features/check-plugin-deactivated.feature index 3df6d38..53a0fdb 100644 --- a/features/check-plugin-deactivated.feature +++ b/features/check-plugin-deactivated.feature @@ -42,3 +42,21 @@ Feature: Check whether a high percentage of plugins are deactivated Then STDOUT should be a table containing rows: | name | status | message | | plugin-deactivated | warning | Greater than 60 percent of plugins are deactivated. | + + Scenario: Gracefully handle no plugins installed + Given a WP install + And I run `wp plugin uninstall --all` + + When I run `wp doctor check plugin-deactivated` + Then STDOUT should be a table containing rows: + | name | status | message | + | plugin-deactivated | success | Less than 40 percent of plugins are deactivated. | + + Scenario: Gracefully handle only network-enabled plugins installed and activated + Given a WP multisite installation + And I run `wp plugin activate --network --all` + + When I run `wp doctor check plugin-deactivated` + Then STDOUT should be a table containing rows: + | name | status | message | + | plugin-deactivated | success | Less than 40 percent of plugins are deactivated. | diff --git a/src/Check.php b/src/Check.php index f4c08af..c0fc4e2 100644 --- a/src/Check.php +++ b/src/Check.php @@ -99,5 +99,4 @@ public function get_results() { 'message' => $this->_message, ); } - } diff --git a/src/Check/AutoloadOptionsSize.php b/src/Check/AutoloadOptionsSize.php index cf25ce9..42911ef 100644 --- a/src/Check/AutoloadOptionsSize.php +++ b/src/Check/AutoloadOptionsSize.php @@ -38,7 +38,6 @@ public function run() { $this->set_status( 'success' ); $this->set_message( "Autoloaded options size ({$human_total}) is less than threshold ({$human_threshold})." ); } - } private static function format_bytes( $size, $precision = 2 ) { @@ -46,5 +45,4 @@ private static function format_bytes( $size, $precision = 2 ) { $suffixes = array( '', 'kb', 'mb', 'g', 't' ); return round( pow( 1024, $base - floor( $base ) ), $precision ) . $suffixes[ floor( $base ) ]; } - } diff --git a/src/Check/CacheFlush.php b/src/Check/CacheFlush.php index 6d7ccca..e89bcf8 100644 --- a/src/Check/CacheFlush.php +++ b/src/Check/CacheFlush.php @@ -7,7 +7,7 @@ use WP_CLI; /** - * Detects the number of occurrences of the `wp_cache_flush()` function. + * Detects any use of the `wp_cache_flush()` function. */ class CacheFlush extends FileContents { diff --git a/src/Check/ConstantDefinition.php b/src/Check/ConstantDefinition.php index c98f08c..4b6fbe3 100644 --- a/src/Check/ConstantDefinition.php +++ b/src/Check/ConstantDefinition.php @@ -70,14 +70,12 @@ public function run() { $this->set_status( 'error' ); $this->set_message( "Constant '{$this->constant}' is defined '{$human_actual}' but expected to not be falsy." ); } - } else { - if ( ! $this->falsy ) { + } elseif ( ! $this->falsy ) { $this->set_status( 'success' ); $this->set_message( "Constant '{$this->constant}' is not defined falsy." ); - } else { - $this->set_status( 'error' ); - $this->set_message( "Constant '{$this->constant}' is defined '{$human_actual}' but expected to be falsy." ); - } + } else { + $this->set_status( 'error' ); + $this->set_message( "Constant '{$this->constant}' is defined '{$human_actual}' but expected to be falsy." ); } } return; @@ -119,7 +117,6 @@ public function run() { $human_expected = self::human_value( $this->value ); $this->set_message( "Constant '{$this->constant}' is defined '{$human_actual}' but expected to be '{$human_expected}'." ); } - } private static function human_value( $value ) { @@ -130,5 +127,4 @@ private static function human_value( $value ) { } return $value; } - } diff --git a/src/Check/CoreUpdate.php b/src/Check/CoreUpdate.php index 84dc76f..90e4ac4 100644 --- a/src/Check/CoreUpdate.php +++ b/src/Check/CoreUpdate.php @@ -38,7 +38,5 @@ public function run() { $this->set_status( 'success' ); $this->set_message( 'WordPress is at the latest version.' ); } - } - } diff --git a/src/Check/CoreVerifyChecksums.php b/src/Check/CoreVerifyChecksums.php index b4c84b9..0ae03ff 100644 --- a/src/Check/CoreVerifyChecksums.php +++ b/src/Check/CoreVerifyChecksums.php @@ -31,5 +31,4 @@ public function run() { $this->set_message( "WordPress doesn't verify against its checksums." ); } } - } diff --git a/src/Check/Cron.php b/src/Check/Cron.php index c9b7cd9..e83ace1 100644 --- a/src/Check/Cron.php +++ b/src/Check/Cron.php @@ -21,5 +21,4 @@ protected static function get_crons() { self::$crons = ! empty( $ret ) ? json_decode( $ret, true ) : array(); return self::$crons; } - } diff --git a/src/Check/CronCount.php b/src/Check/CronCount.php index b32533c..bdc40f3 100644 --- a/src/Check/CronCount.php +++ b/src/Check/CronCount.php @@ -26,5 +26,4 @@ public function run() { $this->set_message( 'Total number of cron jobs is within normal operating expectations.' ); } } - } diff --git a/src/Check/CronDuplicates.php b/src/Check/CronDuplicates.php index 3be5ce1..6a0c735 100644 --- a/src/Check/CronDuplicates.php +++ b/src/Check/CronDuplicates.php @@ -24,7 +24,7 @@ public function run() { if ( ! isset( $job_counts[ $job['hook'] ] ) ) { $job_counts[ $job['hook'] ] = 0; } - $job_counts[ $job['hook'] ]++; + ++$job_counts[ $job['hook'] ]; if ( $job_counts[ $job['hook'] ] >= $this->threshold_count ) { $excess_duplicates = true; } @@ -37,5 +37,4 @@ public function run() { $this->set_message( 'All cron job counts are within normal operating expectations.' ); } } - } diff --git a/src/Check/File.php b/src/Check/File.php index 25168a2..fc1b496 100644 --- a/src/Check/File.php +++ b/src/Check/File.php @@ -58,5 +58,4 @@ public function get_options() { 'path' => $this->path, ); } - } diff --git a/src/Check/FileType.php b/src/Check/FileType.php index f7d1904..beb9ae1 100644 --- a/src/Check/FileType.php +++ b/src/Check/FileType.php @@ -30,7 +30,6 @@ public function run() { $this->set_message( "All '{$this->extension}' files passed assertion that symlink is '{$symlink}'." ); } } - } public function check_file( SplFileInfo $file ) { @@ -42,5 +41,4 @@ public function check_file( SplFileInfo $file ) { } } } - } diff --git a/src/Check/OptionValue.php b/src/Check/OptionValue.php index bca2350..43158dd 100644 --- a/src/Check/OptionValue.php +++ b/src/Check/OptionValue.php @@ -42,7 +42,7 @@ public function run() { $actual_value = get_option( $this->option ); if ( isset( $this->value ) ) { - if ( $actual_value == $this->value ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- Keep existing behavior. + if ( $actual_value == $this->value ) { // phpcs:ignore Universal.Operators.StrictComparisons -- Keep existing behavior. $status = 'success'; $message = "Option '{$this->option}' is '{$this->value}' as expected."; } else { @@ -50,7 +50,7 @@ public function run() { $message = "Option '{$this->option}' is '{$actual_value}' but expected to be '{$this->value}'."; } } elseif ( isset( $this->value_is_not ) ) { - if ( $actual_value == $this->value_is_not ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- Keep existing behavior. + if ( $actual_value == $this->value_is_not ) { // phpcs:ignore Universal.Operators.StrictComparisons -- Keep existing behavior. $status = 'error'; $message = "Option '{$this->option}' is '{$actual_value}' and expected not to be."; } else { @@ -78,7 +78,5 @@ public function run() { # code... break; } - } - } diff --git a/src/Check/Plugin.php b/src/Check/Plugin.php index 3975c90..b759be9 100644 --- a/src/Check/Plugin.php +++ b/src/Check/Plugin.php @@ -21,5 +21,4 @@ protected static function get_plugins() { self::$plugins = ! empty( $ret ) ? json_decode( $ret, true ) : array(); return self::$plugins; } - } diff --git a/src/Check/PluginActiveCount.php b/src/Check/PluginActiveCount.php index 4b98d5f..5bf8b21 100644 --- a/src/Check/PluginActiveCount.php +++ b/src/Check/PluginActiveCount.php @@ -21,8 +21,8 @@ public function run() { $active = 0; foreach ( self::get_plugins() as $plugin ) { - if ( 'active' === $plugin['status'] ) { - $active++; + if ( 'active' === $plugin['status'] || 'active-network' === $plugin['status'] ) { + ++$active; } } @@ -34,7 +34,5 @@ public function run() { $this->set_status( 'success' ); $this->set_message( "Number of active plugins ({$active}) is less than threshold ({$threshold})." ); } - } - } diff --git a/src/Check/PluginDeactivated.php b/src/Check/PluginDeactivated.php index 0efde78..f7abf67 100644 --- a/src/Check/PluginDeactivated.php +++ b/src/Check/PluginDeactivated.php @@ -22,22 +22,20 @@ public function run() { $active = 0; $inactive = 0; foreach ( self::get_plugins() as $plugin ) { - if ( 'active' === $plugin['status'] ) { - $active++; + if ( 'active' === $plugin['status'] || 'active-network' === $plugin['status'] ) { + ++$active; } elseif ( 'inactive' === $plugin['status'] ) { - $inactive++; + ++$inactive; } } $threshold = (int) $this->threshold_percentage; - if ( ( $inactive / ( $inactive + $active ) ) > ( $threshold / 100 ) ) { + if ( $inactive + $active > 0 && ( $inactive / ( $inactive + $active ) ) > ( $threshold / 100 ) ) { $this->set_status( 'warning' ); $this->set_message( "Greater than {$threshold} percent of plugins are deactivated." ); } else { $this->set_status( 'success' ); $this->set_message( "Less than {$threshold} percent of plugins are deactivated." ); } - } - } diff --git a/src/Check/PluginStatus.php b/src/Check/PluginStatus.php index bcb1328..40525ea 100644 --- a/src/Check/PluginStatus.php +++ b/src/Check/PluginStatus.php @@ -66,5 +66,4 @@ public function run() { $this->set_message( "Plugin '{$this->name}' is '{$current_status}' as expected." ); } } - } diff --git a/src/Check/PluginUpdate.php b/src/Check/PluginUpdate.php index e8555c1..3c0555a 100644 --- a/src/Check/PluginUpdate.php +++ b/src/Check/PluginUpdate.php @@ -14,7 +14,7 @@ public function run() { $update_count = 0; foreach ( $plugins as $plugin ) { if ( 'available' === $plugin['update'] ) { - $update_count++; + ++$update_count; } } @@ -28,7 +28,5 @@ public function run() { $this->set_status( 'success' ); $this->set_message( 'Plugins are up to date.' ); } - } - } diff --git a/src/Check/ThemeUpdate.php b/src/Check/ThemeUpdate.php index dc27dad..409905c 100644 --- a/src/Check/ThemeUpdate.php +++ b/src/Check/ThemeUpdate.php @@ -18,7 +18,7 @@ public function run() { $update_count = 0; foreach ( $themes as $theme ) { if ( 'available' === $theme['update'] ) { - $update_count++; + ++$update_count; } } @@ -32,7 +32,5 @@ public function run() { $this->set_status( 'success' ); $this->set_message( 'Themes are up to date.' ); } - } - } diff --git a/src/Checks.php b/src/Checks.php index 5e11006..a2d32d0 100644 --- a/src/Checks.php +++ b/src/Checks.php @@ -35,7 +35,7 @@ public static function register_config( $file ) { if ( ! empty( $check_data['_']['inherit'] ) ) { $inherited = $check_data['_']['inherit']; if ( 'default' === $inherited ) { - $inherited = dirname( dirname( __FILE__ ) ) . '/doctor.yml'; + $inherited = dirname( __DIR__ ) . '/doctor.yml'; } $inherited = self::absolutize( $inherited, dirname( $file ) ); if ( isset( $check_data['_']['skipped_checks'] ) ) { diff --git a/src/Command.php b/src/Command.php index ead796c..aa568f7 100644 --- a/src/Command.php +++ b/src/Command.php @@ -185,7 +185,7 @@ static function () { $check_count = count( $results ); $results = array_filter( $results, - function( $check ) { + function ( $check ) { return in_array( $check['status'], array( 'warning', 'error' ), true ); } ); @@ -202,14 +202,14 @@ function( $check ) { $results_with_error = array_filter( $results, - function( $check ) { + function ( $check ) { return 'error' === $check['status']; } ); $should_error = ! empty( $results_with_error ); if ( $should_error && 'table' === $assoc_args['format'] ) { $check_count = count( $results_with_error ); - $error_message = 1 === $check_count ? "1 check reports 'error'." : "${check_count} checks report 'error'."; + $error_message = 1 === $check_count ? "1 check reports 'error'." : sprintf( "%d checks report 'error'.", $check_count ); } else { $error_message = null; } @@ -309,7 +309,7 @@ private function load_wordpress_with_template() { WP_CLI::add_wp_hook( 'wp_redirect', - function( $to ) { + function ( $to ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter ob_start(); debug_print_backtrace(); $message = ob_get_clean(); @@ -372,7 +372,6 @@ private static function remove_decorations( $comment ) { * Get the path to the default config file */ private static function get_default_config() { - return dirname( dirname( __FILE__ ) ) . '/doctor.yml'; + return dirname( __DIR__ ) . '/doctor.yml'; } - }