diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 6bc4d107..8a17c256 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -19,9 +19,9 @@ To determine where best to report the bug, use the first part of the sniff name: Sniff name starts with | Report to --- | --- -`Generic` | [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/issues/) -`PSR2` | [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/issues/) -`Squiz` | [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer/issues/) +`Generic` | [PHP_CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/) +`PSR2` | [PHP_CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/) +`Squiz` | [PHP_CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/) `Universal` | [PHPCSExtra](https://github.com/PHPCSStandards/PHPCSExtra/issues/) `VariableAnalysis` | [VariableAnalysis](https://github.com/sirbrillig/phpcs-variable-analysis/issues/) `WordPress` | [WordPressCS](https://github.com/WordPress/WordPress-Coding-Standards/issues/) @@ -29,6 +29,32 @@ Sniff name starts with | Report to ---- +## Getting the source files + +```sh +git clone git@github.com:Automattic/VIP-Coding-Standards.git vipcs +``` + +...or: + +```sh +gh repo clone Automattic/VIP-Coding-Standards vipcs +``` + +Now `cd vipcs` and run: + +```sh +composer install +``` + +You can now run: + +``` +composer check +``` + +... and all checks should pass. + ## tl;dr Composer Scripts This package contains Composer scripts to quickly run the developer checks which are described (with setups) further below. @@ -67,7 +93,7 @@ When you introduce new `public` sniff properties, or your sniff extends a class * WordPress-Coding-Standards * PHPCSUtils 1.x * PHP_CodeSniffer 3.x -* PHPUnit 4.x, 5.x, 6.x or 7.x +* PHPUnit 4.x - 9.x The VIP Coding Standards use the PHP_CodeSniffer native unit test suite for unit testing the sniffs. @@ -78,7 +104,7 @@ N.B.: If you installed VIPCS using Composer, make sure you used `--prefer-source If you already have PHPUnit installed on your system: Congrats, you're all set. If not, you can navigate to the directory where the `PHP_CodeSniffer` repo is checked out and do `composer install` to install the `dev` dependencies. -Alternatively, you can [install PHPUnit](https://phpunit.readthedocs.io/en/7.5/installation.html) as a PHAR file. +Alternatively, you can [install PHPUnit](https://phpunit.readthedocs.io/en/9.6/installation.html) as a PHAR file. ### Before running the unit tests @@ -118,7 +144,7 @@ The easiest way to do this is to add a `phpunit.xml` file to the root of your VI Expected output: ``` -PHPUnit 7.5.20 by Sebastian Bergmann and contributors. +PHPUnit 9.6.15 by Sebastian Bergmann and contributors. ........................................ 40 / 40 (100%) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 5bfbcec3..be9552ec 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -47,6 +47,7 @@ Use `php -v` and `composer show` to get versions. | PHPCSUtils version | x.y.z | VIPCS version | x.y.z | WordPressCS version | x.y.z +| PHPCSExtra version | x.y.z | VariableAnalysis version | x.y.z ## Additional Context (optional) diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..3c13fc31 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,16 @@ +# Dependabot configuration. +# +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + time: "09:00" + commit-message: + prefix: "GH Actions:" + labels: + - "Type: Maintenance" diff --git a/.github/workflows/basics.yml b/.github/workflows/basics.yml index 7e616537..8a6c8fa1 100644 --- a/.github/workflows/basics.yml +++ b/.github/workflows/basics.yml @@ -24,7 +24,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -33,14 +33,20 @@ jobs: coverage: none tools: cs2pr + # Updating the lists can fail intermittently, typically after Microsoft has released a new package. + # This should not be blocking for this job, so ignore any errors from this step. + # Ref: https://github.com/dotnet/core/issues/4167 + - name: Update the available packages list + continue-on-error: true + run: sudo apt-get update + - name: Install xmllint - run: | - sudo apt-get update - sudo apt-get install --no-install-recommends -y libxml2-utils + run: sudo apt-get install --no-install-recommends -y libxml2-utils # Show XML violations inline in the file diff. # @link https://github.com/marketplace/actions/xmllint-problem-matcher - - uses: korelstar/xmllint-problem-matcher@v1 + - name: Enable showing XML issues inline + uses: korelstar/xmllint-problem-matcher@v1 # Validate the composer.json file. # @link https://getcomposer.org/doc/03-cli.md#validate @@ -52,9 +58,9 @@ jobs: run: composer require --no-update --no-scripts squizlabs/php_codesniffer:"dev-master" --no-interaction # Install dependencies and handle caching in one go. - # @link https://github.com/marketplace/actions/install-composer-dependencies + # @link https://github.com/marketplace/actions/install-php-dependencies-with-composer - name: Install Composer dependencies - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") @@ -84,20 +90,20 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: 'latest' coverage: none tools: phpstan # Install dependencies and handle caching in one go. # Dependencies need to be installed to make sure the PHPCS and PHPUnit classes are recognized. - # @link https://github.com/marketplace/actions/install-composer-dependencies + # @link https://github.com/marketplace/actions/install-php-dependencies-with-composer - name: Install Composer dependencies - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml index becaac4c..fff3cfa4 100644 --- a/.github/workflows/quicktest.yml +++ b/.github/workflows/quicktest.yml @@ -40,7 +40,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up PHP uses: shivammathur/setup-php@v2 @@ -52,25 +52,15 @@ jobs: coverage: none # Install dependencies and handle caching in one go. - # @link https://github.com/marketplace/actions/install-composer-dependencies - - name: Install Composer dependencies - normal - if: ${{ startsWith( matrix.php, '8' ) == false && matrix.php != 'latest' }} - uses: "ramsey/composer-install@v2" + # @link https://github.com/marketplace/actions/install-php-dependencies-with-composer + - name: Install Composer dependencies + uses: "ramsey/composer-install@v3" with: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") - # PHPUnit 7.x does not allow for installation on PHP 8, so ignore platform - # requirements to get PHPUnit 7.x to install on nightly. - - name: Install Composer dependencies - with ignore platform - if: ${{ startsWith( matrix.php, '8' ) || matrix.php == 'latest' }} - uses: "ramsey/composer-install@v2" - with: - composer-options: --ignore-platform-req=php+ - custom-cache-suffix: $(date -u "+%Y-%m") - - name: "Composer: downgrade PHPCS dependencies for tests (lowest)" - if: ${{ matrix.php == '5.4' && matrix.dependencies == 'lowest' }} + if: ${{ matrix.dependencies == 'lowest' }} run: > composer update --prefer-lowest --no-scripts --no-interaction squizlabs/php_codesniffer @@ -79,16 +69,6 @@ jobs: sirbrillig/phpcs-variable-analysis wp-coding-standards/wpcs - - name: "Composer: downgrade PHPCS dependencies for tests (lowest) - with ignore platform" - if: ${{ matrix.php == 'latest' && matrix.dependencies == 'lowest' }} - run: > - composer update --prefer-lowest --no-scripts --no-interaction --ignore-platform-req=php+ - squizlabs/php_codesniffer - phpcsstandards/phpcsutils - phpcsstandards/phpcsextra - sirbrillig/phpcs-variable-analysis - wp-coding-standards/wpcs - - name: Display PHPCS installed standards run: ./vendor/bin/phpcs -i diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cc5ed0a6..ab08a031 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,14 +28,14 @@ jobs: strategy: matrix: - php: ['5.4', 'latest', '8.3'] + php: ['5.4', 'latest', '8.4'] name: "Lint: PHP ${{ matrix.php }}" - continue-on-error: ${{ matrix.php == '8.3' }} + continue-on-error: ${{ matrix.php == '8.4' }} steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Install PHP uses: shivammathur/setup-php@v2 @@ -45,7 +45,7 @@ jobs: tools: cs2pr - name: Install Composer dependencies - uses: "ramsey/composer-install@v2" + uses: "ramsey/composer-install@v3" with: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") @@ -67,8 +67,9 @@ jobs: # - PHPCS will run without errors on PHP 5.4 - 7.4 on any supported version. # - PHP 8.0 needs PHPCS 3.5.7+ to run without errors, and we require a higher minimum version. # - PHP 8.1 needs PHPCS 3.6.1+ to run without errors, but works best with 3.7.1+, and we require at least this minimum version. + # - PHP 8.2 and 8.3 need PHPCS 3.8.0+ to run without errors (though the errors don't affect the tests). matrix: - php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2'] + php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] dependencies: ['lowest', 'stable'] include: @@ -79,20 +80,20 @@ jobs: dependencies: 'dev' - php: '7.4' dependencies: 'dev' - - php: '8.2' + - php: '8.3' dependencies: 'dev' # Test against upcoming PHP version. - - php: '8.3' + - php: '8.4' dependencies: 'dev' name: "Test: PHP ${{ matrix.php }} - PHPCS ${{ matrix.dependencies }}" - continue-on-error: ${{ matrix.php == '8.3' }} + continue-on-error: ${{ matrix.php == '8.4' }} steps: - name: Checkout code - uses: actions/checkout@v3 + uses: actions/checkout@v4 # With stable PHPCS dependencies, allow for PHP deprecation notices. # Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore. @@ -123,25 +124,15 @@ jobs: wp-coding-standards/wpcs:"dev-develop" # Install dependencies and handle caching in one go. - # @link https://github.com/marketplace/actions/install-composer-dependencies - - name: Install Composer dependencies - normal - if: ${{ startsWith( matrix.php, '8' ) == false }} - uses: "ramsey/composer-install@v2" + # @link https://github.com/marketplace/actions/install-php-dependencies-with-composer + - name: Install Composer dependencies + uses: "ramsey/composer-install@v3" with: # Bust the cache at least once a month - output format: YYYY-MM. custom-cache-suffix: $(date -u "+%Y-%m") - # PHPUnit 7.x does not allow for installation on PHP 8, so ignore platform - # requirements to get PHPUnit 7.x to install on nightly. - - name: Install Composer dependencies - with ignore platform - if: ${{ startsWith( matrix.php, '8' ) }} - uses: "ramsey/composer-install@v2" - with: - composer-options: --ignore-platform-req=php+ - custom-cache-suffix: $(date -u "+%Y-%m") - - name: "Composer: downgrade PHPCS dependencies for tests (lowest)" - if: ${{ ! startsWith( matrix.php, '8' ) && matrix.dependencies == 'lowest' }} + if: ${{ matrix.dependencies == 'lowest' }} run: > composer update --prefer-lowest --no-scripts --no-interaction squizlabs/php_codesniffer @@ -150,16 +141,6 @@ jobs: sirbrillig/phpcs-variable-analysis wp-coding-standards/wpcs - - name: "Composer: downgrade PHPCS dependencies for tests (lowest) - with ignore platform" - if: ${{ startsWith( matrix.php, '8' ) && matrix.dependencies == 'lowest' }} - run: > - composer update --prefer-lowest --no-scripts --no-interaction --ignore-platform-req=php+ - squizlabs/php_codesniffer - phpcsstandards/phpcsutils - phpcsstandards/phpcsextra - sirbrillig/phpcs-variable-analysis - wp-coding-standards/wpcs - - name: Run the unit tests run: ./bin/unit-tests diff --git a/.gitignore b/.gitignore index 8c5b8732..843c4b83 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ phpcs.xml phpunit.xml phpcs.cache phpstan.neon +.phpunit.result.cache diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index a0049b7b..098e5acb 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -1,5 +1,5 @@ - + The custom ruleset for the VIP Coding Standards itself. . diff --git a/CHANGELOG.md b/CHANGELOG.md index 1105bddb..3e04b2ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,41 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.0.1] - 2024-05-14 + +Props: @GaryJones, @jrnfl, @terriann, @rebeccahum + +Increases requirements for PHPCS from 3.7.2 to 3.9.2 for improved PHP 8.2 and PHP 8.3 support. Please ensure you run `composer update automattic/vipwpcs --with-dependencies` to benefit from this. + +### Removed +- Functions/RestrictedFunctions: + * [#812](https://github.com/Automattic/VIP-Coding-Standards/pull/812): Remove restricting `term_exists()`. + * [#814](https://github.com/Automattic/VIP-Coding-Standards/pull/814): Remove restricting `get_page_by_title()`. + * [#817](https://github.com/Automattic/VIP-Coding-Standards/pull/817): Remove restricting `get_page_by_path()`. + +### Changed +- [#799](https://github.com/Automattic/VIP-Coding-Standards/pull/799): Classes/DeclarationCompatibility: Sync signature definitions with WP Core. + +### Maintenance +- [#797](https://github.com/Automattic/VIP-Coding-Standards/pull/797): GH: Add initial dependabot config file. +- GH Actions: + * [#798](https://github.com/Automattic/VIP-Coding-Standards/pull/798): Bump actions/checkout to 4 from 3. + * [#802](https://github.com/Automattic/VIP-Coding-Standards/pull/802): Minor tweaks of updating an incorrect URL and adding names to steps. + * [#803](https://github.com/Automattic/VIP-Coding-Standards/pull/802): Builds against PHP 8.3 can no longer fail, but 8.4 can. + * [#818](https://github.com/Automattic/VIP-Coding-Standards/pull/818): Add workaround for intermittent `apt-get update` issue. +- Composer: + * [#805](https://github.com/Automattic/VIP-Coding-Standards/pull/805): Raise minimum version for better PHP 8.2 support. + * [#805](https://github.com/Automattic/VIP-Coding-Standards/pull/805): Up the minimum PHPCSExtra version to 1.2.1. + * [#821](https://github.com/Automattic/VIP-Coding-Standards/pull/821): Up the minimum PHPCSUtils version to 1.0.11. + * [#821](https://github.com/Automattic/VIP-Coding-Standards/pull/821): Up the minimum PHPCS version to 3.9.2. + * [#821](https://github.com/Automattic/VIP-Coding-Standards/pull/821): Up the minimum WPCS version to 3.1.0. + * [#821](https://github.com/Automattic/VIP-Coding-Standards/pull/821): Up the minimum PHPCSVariableAnalysis version to 2.11.18. +- Docs: + * [#805](https://github.com/Automattic/VIP-Coding-Standards/pull/805): Update references to PHPCS under PHPCSStandards, as squizlabs version is abandoned. + * [#808](https://github.com/Automattic/VIP-Coding-Standards/pull/808): Update Composer installation instructions. + * [#811](https://github.com/Automattic/VIP-Coding-Standards/pull/811): Update old URLs. +- [#809](https://github.com/Automattic/VIP-Coding-Standards/pull/809): Unit tests: Allow for PHPUnit 8 and 9. + ## [3.0.0] - 2023-09-05 Props: @GaryJones, @jrfnl @@ -18,7 +53,7 @@ The tagged releases branch is now `main` instead of `master`. - [#777](https://github.com/Automattic/VIP-Coding-Standards/pull/777): 3.0: start using PHPCSUtils. - [#779](https://github.com/Automattic/VIP-Coding-Standards/pull/779): 3.0: support WordPressCS 3.0. -## Changed +### Changed - [#780](https://github.com/Automattic/VIP-Coding-Standards/pull/780): Performance/WPQueryParams: defer to the parent sniff. - Two error codes changed: - `WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn` is now `WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in`. @@ -674,6 +709,7 @@ Initial release. Props: david-binda, pkevan. +[3.0.1]: https://github.com/Automattic/VIP-Coding-Standards/compare/3.0.0...3.0.1 [3.0.0]: https://github.com/Automattic/VIP-Coding-Standards/compare/2.3.4...3.0.0 [2.3.4]: https://github.com/Automattic/VIP-Coding-Standards/compare/2.3.3...2.3.4 [2.3.3]: https://github.com/Automattic/VIP-Coding-Standards/compare/2.3.2...2.3.3 diff --git a/LICENSE.md b/LICENSE.md index b6197d02..5517f00d 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -64,4 +64,4 @@ Included Files This project includes: - [WordPress-Coding-Standards](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards), which is Copyright © 2009 John Godley and contributors. Released under the MIT license https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/blob/develop/LICENSE -- [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer), Copyright © 2012, Squiz Pty Ltd (ABN 77 084 670 600). Released under the following license: https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt +- [PHP_CodeSniffer](https://github.com/PHPCSStandards/PHP_CodeSniffer), Copyright © 2012, Squiz Pty Ltd (ABN 77 084 670 600). Released under the following license: https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt diff --git a/README.md b/README.md index 1006b175..c0d08b3f 100644 --- a/README.md +++ b/README.md @@ -1,45 +1,52 @@ # VIP Coding Standards -This project contains [PHP_CodeSniffer (PHPCS) sniffs and rulesets](https://github.com/squizlabs/PHP_CodeSniffer) to validate code developed for [WordPress VIP](https://wpvip.com/). +This project contains [PHP_CodeSniffer (PHPCS) sniffs and rulesets](https://github.com/PHPCSStandards/PHP_CodeSniffer) to validate code developed for [WordPress VIP](https://wpvip.com/). This project contains two rulesets: - `WordPressVIPMinimum` - for use with projects on the (older) WordPress.com VIP platform. - `WordPress-VIP-Go` - for use with projects on the (newer) VIP Go platform. -These rulesets contain only the rules which are considered to be ["errors"](https://docs.wpvip.com/technical-references/code-review/vip-errors/) and ["warnings"](https://docs.wpvip.com/technical-references/code-review/vip-warnings/) according to the WordPress VIP Go documentation. +These rulesets contain only the rules which are considered to be [errors](https://docs.wpvip.com/php_codesniffer/errors/) and [warnings](https://docs.wpvip.com/php_codesniffer/warnings/) according to the WordPress VIP documentation. The rulesets use rules from the [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards) (WPCS) project, as well as the [VariableAnalysis](https://github.com/sirbrillig/phpcs-variable-analysis) standard. -Go to https://docs.wpvip.com/technical-references/code-review/phpcs-report/ to learn about why violations are flagged as errors vs warnings and what the levels mean. +[Learn](https://docs.wpvip.com/vip-code-analysis-bot/phpcs-report/) about why violations are flagged as errors vs warnings and what the levels mean. ## Minimal requirements * PHP 5.4+ -* [PHPCS 3.7.2+](https://github.com/squizlabs/PHP_CodeSniffer/releases) -* [PHPCSUtils 1.0.8+](https://github.com/PHPCSStandards/PHPCSUtils) +* [PHPCS 3.8.0+](https://github.com/PHPCSStandards/PHP_CodeSniffer/releases) +* [PHPCSUtils 1.0.9+](https://github.com/PHPCSStandards/PHPCSUtils) +* [PHPCSExtra 1.2.1+](https://github.com/PHPCSStandards/PHPCSExtra) * [WPCS 3.0.0+](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/releases) * [VariableAnalysis 2.11.17+](https://github.com/sirbrillig/phpcs-variable-analysis/releases) ## Installation -To install the VIP Coding Standards, run: -```bash -composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true -composer require automattic/vipwpcs -``` +[Composer](https://getcomposer.org/) will install the latest compatible versions of PHPCS, PHPCSUtils, PHPCSExtra, WPCS and VariableAnalysis and register the external standards with PHP_CodeSniffer. + +Please refer to the [installation instructions for installing PHP_CodeSniffer for WordPress VIP](https://docs.wpvip.com/how-tos/code-review/php_codesniffer/) for more details. + +As of VIPCS version 2.3.0, there is no need to `require` the [PHP_CodeSniffer Standards Composer Installer Plugin](https://github.com/PHPCSStandards/composer-installer) anymore as it is now a requirement of VIPCS itself. Permission to run the plugin will still need to be granted though when using Composer 2.2 or higher. + +### Composer Project-based Installation + +To install the VIP Coding Standards, run the following from the root of your project: -or if installing globally: ```bash -composer g config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true -composer g require automattic/vipwpcs +composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true +composer require --dev automattic/vipwpcs ``` -This will install the latest compatible versions of PHPCS, PHPCSUtils, PHPCSExtra, WPCS and VariableAnalysis and register the external standards with PHP_CodeSniffer. +### Composer Global Installation -Please refer to the [installation instructions for installing PHP_CodeSniffer for WordPress.com VIP](https://docs.wpvip.com/how-tos/code-review/php_codesniffer/) for more details. +Alternatively, it can be installed standard globally for use across multiple projects: -As of VIPCS version 2.3.0, there is no need to `require` the [PHP_CodeSniffer Standards Composer Installer Plugin](https://github.com/PHPCSStandards/composer-installer) anymore as it is now a requirement of VIPCS itself. Permission to run the plugin will still need to be granted though when using Composer 2.2 or higher. +```bash +composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true +composer global require --dev automattic/vipwpcs +``` ## Contribution diff --git a/WordPress-VIP-Go/ruleset-test.inc b/WordPress-VIP-Go/ruleset-test.inc index 773842b0..bd7e3de6 100644 --- a/WordPress-VIP-Go/ruleset-test.inc +++ b/WordPress-VIP-Go/ruleset-test.inc @@ -130,9 +130,9 @@ get_next_post(); // Warning. get_previous_post_link(); // Warning. get_next_post_link(); // Warning. -// WordPressVIPMinimum.Functions.RestrictedFunctions.get_page_by_title_get_page_by_title -wpcom_vip_get_page_by_title(); // Ok. -get_page_by_title( $page_title ); // Warning + Message. + + + // WordPressVIPMinimum.Functions.RestrictedFunctions.get_posts_get_children get_child(); // Ok. @@ -358,7 +358,7 @@ wpcom_vip_irc(); // Error. flush_rewrite_rules(); // Error. $wp_rewrite->flush_rules(); // Error. \add_role(); // Error. -term_exists(); // Error. + count_user_posts(); // Error. get_intermediate_image_sizes(); // Error. wp_is_mobile(); // Error. diff --git a/WordPress-VIP-Go/ruleset-test.php b/WordPress-VIP-Go/ruleset-test.php index 0fde7fbe..d8701db4 100644 --- a/WordPress-VIP-Go/ruleset-test.php +++ b/WordPress-VIP-Go/ruleset-test.php @@ -47,7 +47,6 @@ 358 => 1, 359 => 1, 360 => 1, - 361 => 1, 362 => 1, 363 => 1, 364 => 1, @@ -155,7 +154,6 @@ 129 => 1, 130 => 1, 131 => 1, - 135 => 1, 139 => 1, 142 => 1, 146 => 1, @@ -305,9 +303,6 @@ 123 => [ 'attachment_url_to_postid() is uncached, please use wpcom_vip_attachment_url_to_postid() instead.', ], - 135 => [ - 'get_page_by_title() is uncached, please use wpcom_vip_get_page_by_title() instead.', - ], 139 => [ 'get_children() is uncached and performs a no limit query. Please use get_posts or WP_Query instead. Please see: https://docs.wpvip.com/technical-references/caching/uncached-functions/', ], diff --git a/WordPress-VIP-Go/ruleset.xml b/WordPress-VIP-Go/ruleset.xml index 190bebc8..8cd531c3 100644 --- a/WordPress-VIP-Go/ruleset.xml +++ b/WordPress-VIP-Go/ruleset.xml @@ -1,5 +1,5 @@ - + WordPress VIP Go Coding Standards @@ -152,10 +152,6 @@ warning - - warning - %s() is uncached, please use wpcom_vip_get_page_by_title() instead. - warning 3 diff --git a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php index 712cacd0..a71b4907 100644 --- a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php +++ b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php @@ -40,7 +40,7 @@ class DeclarationCompatibilitySniff extends AbstractScopeSniff { 'widget_options' => [ 'default' => 'array()', ], - 'constol_options' => [ + 'control_options' => [ 'default' => 'array()', ], ], @@ -103,7 +103,7 @@ class DeclarationCompatibilitySniff extends AbstractScopeSniff { 'output' => [ 'pass_by_reference' => true, ], - 'object', + 'data_object', 'depth' => [ 'default' => '0', ], @@ -118,7 +118,7 @@ class DeclarationCompatibilitySniff extends AbstractScopeSniff { 'output' => [ 'pass_by_reference' => true, ], - 'object', + 'data_object', 'depth' => [ 'default' => '0', ], @@ -158,7 +158,7 @@ class DeclarationCompatibilitySniff extends AbstractScopeSniff { 'elements', ], 'unset_children' => [ - 'el', + 'element', 'children_elements' => [ 'pass_by_reference' => true, ], @@ -215,7 +215,7 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco return; } - // Meed to define the originalParentClassName since we might override the parentClassName due to signature notations grouping. + // Need to define the originalParentClassName since we might override the parentClassName due to signature notations grouping. $originalParentClassName = $parentClassName; if ( array_key_exists( $parentClassName, $this->checkClasses ) === false ) { diff --git a/WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php b/WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php index 505bc5a0..4513140c 100644 --- a/WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php +++ b/WordPressVIPMinimum/Sniffs/Functions/RestrictedFunctionsSniff.php @@ -80,13 +80,6 @@ public function getGroups() { 'switch_to_blog', ], ], - 'get_page_by_title' => [ - 'type' => 'error', - 'message' => '%s() is prohibited, please use wpcom_vip_get_page_by_title() instead.', - 'functions' => [ - 'get_page_by_title', - ], - ], 'url_to_postid' => [ 'type' => 'error', 'message' => '%s() is prohibited, please use wpcom_vip_url_to_postid() instead.', @@ -102,13 +95,6 @@ public function getGroups() { 'add_role', ], ], - 'term_exists' => [ - 'type' => 'error', - 'message' => '%s() is highly discouraged due to not being cached; please use wpcom_vip_term_exists() instead.', - 'functions' => [ - 'term_exists', - ], - ], 'count_user_posts' => [ 'type' => 'error', 'message' => '%s() is highly discouraged due to not being cached; please use wpcom_vip_count_user_posts() instead.', @@ -283,13 +269,6 @@ public function getGroups() { 'create_function', ], ], - 'get_page_by_path' => [ - 'type' => 'warning', - 'message' => '%s() is highly discouraged due to not being cached; please use wpcom_vip_get_page_by_path() instead.', - 'functions' => [ - 'get_page_by_path', - ], - ], ]; $deprecated_vip_helpers = [ diff --git a/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.inc b/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.inc index a7ecaacf..740a7883 100644 --- a/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.inc +++ b/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.inc @@ -125,15 +125,21 @@ class MyWalker extends Walker { function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { } // Ok. - function unset_children( $el, $children_elements ) { + function unset_children( $element, $children_elements ) { } // Bad. $children_elements should be passed by reference - + function walk( $elements, $max_depth, ...$args ) { } // Ok. - + function paged_walk( $elements, $max_depth, $page_num, $per_page ) { } // Bad. Missing $args. function paged_walk( $elements, $max_depth, $page_num, $per_page, $args ) { } // Bad. $args is not variadic. + + function start_el( $output, $data_object, $depth, $args = array(), $current_object_id = 0 ) { + } // Bad. $output should be passed by reference, $depth should have a default value. + + function end_el( &$output, $data_object, $depth = 0, $args = array() ) { + } // Ok. } diff --git a/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php b/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php index 1a6b89a7..817bc324 100644 --- a/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php +++ b/WordPressVIPMinimum/Tests/Classes/DeclarationCompatibilityUnitTest.php @@ -47,6 +47,7 @@ public function getErrorList() { 128 => 1, 134 => 1, 137 => 1, + 140 => 1, ]; } diff --git a/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.inc b/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.inc index d6dc74ef..19cba6b3 100644 --- a/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.inc +++ b/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.inc @@ -55,8 +55,8 @@ $wp_rewrite->flush_rules(); // Error. switch_blog(); // Ok - similarly-named function to switch_to_blog(). switch_to_blog( $blogid ); // Warning. -wpcom_vip_get_page_by_title(); // Ok - VIP recommended version of get_page_by_title(). -get_page_by_title( $page_title ); // Error. + + wpcom_vip_url_to_postid( $url ); // Ok - VIP recommended version of url_to_postid(). url_to_postid( $url ); // Error. @@ -84,8 +84,8 @@ add_role( 'test' ); // Error. -wpcom_vip_term_exists(); // Ok - VIP recommended version of term_exists(). -term_exists(); // Error. + + wpcom_vip_count_user_posts(); // Ok - VIP recommended version of count_user_posts(). count_user_posts(); // Error. @@ -222,8 +222,8 @@ $wp_random_testing = create_function3( '$a, $b', 'return ( $b / $a ); '); // Ok. -wpcom_vip_get_page_by_path(); // Ok - VIP recommended version of get_page_by_path(). -get_page_by_path( $page_path ); // Warning. + + $popular = stats_get_csv( 'postviews', [ 'days' => 2, 'limit' => 20 ] ); // Error. $popular = custom_stats_get_csv( 'postviews', [ 'days' => 2, 'limit' => 20 ] ); // Ok. diff --git a/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.php b/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.php index e089d78e..0b4fcc5c 100644 --- a/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.php +++ b/WordPressVIPMinimum/Tests/Functions/RestrictedFunctionsUnitTest.php @@ -35,11 +35,9 @@ public function getErrorList() { 43 => 1, 46 => 1, 50 => 1, - 59 => 1, 62 => 1, 75 => 1, 76 => 1, - 88 => 1, 91 => 1, 94 => 1, 97 => 1, @@ -123,7 +121,6 @@ public function getWarningList() { 138 => 1, 139 => 1, 208 => 1, - 226 => 1, ]; } } diff --git a/WordPressVIPMinimum/ruleset-test.inc b/WordPressVIPMinimum/ruleset-test.inc index 0b25bfef..a20a8494 100644 --- a/WordPressVIPMinimum/ruleset-test.inc +++ b/WordPressVIPMinimum/ruleset-test.inc @@ -322,14 +322,14 @@ $wp_rewrite->flush_rules(); // Error. attachment_url_to_postid( $url ); // Error. switch_to_blog( $blogid ); // Warning. -get_page_by_title( $page_title ); // Error. + url_to_postid( $url ); // Error. \add_role(); // Error. -term_exists(); // Error. + count_user_posts(); // Error. wp_old_slug_redirect(); // Error. get_adjacent_post(); // Error. diff --git a/WordPressVIPMinimum/ruleset-test.php b/WordPressVIPMinimum/ruleset-test.php index 05076415..e78ae6a7 100644 --- a/WordPressVIPMinimum/ruleset-test.php +++ b/WordPressVIPMinimum/ruleset-test.php @@ -92,10 +92,8 @@ 320 => 1, 321 => 1, 322 => 1, - 325 => 1, 326 => 1, 327 => 1, - 332 => 1, 333 => 1, 334 => 1, 335 => 1, diff --git a/WordPressVIPMinimum/ruleset.xml b/WordPressVIPMinimum/ruleset.xml index 13670326..6a3f10c1 100644 --- a/WordPressVIPMinimum/ruleset.xml +++ b/WordPressVIPMinimum/ruleset.xml @@ -1,5 +1,5 @@ - + WordPress VIP Minimum Coding Standards