diff --git a/.github/workflows/quicktest.yml b/.github/workflows/quicktest.yml
index 3de35f83..e8fd98b2 100644
--- a/.github/workflows/quicktest.yml
+++ b/.github/workflows/quicktest.yml
@@ -28,18 +28,14 @@ jobs:
include:
- php: '5.4'
phpcs_version: 'dev-master'
- wpcs_version: '2.3.*'
+ wpcs_version: 'dev-develop'
- php: '5.4'
- phpcs_version: '3.5.5'
- wpcs_version: '2.3.*'
+ phpcs_version: '3.7.1'
+ wpcs_version: 'dev-develop'
- php: 'latest'
phpcs_version: 'dev-master'
- wpcs_version: '2.3.*'
- - php: 'latest'
- # PHPCS 3.6.1 is the lowest version of PHPCS which supports PHP 8.1.
- phpcs_version: '3.6.1'
- wpcs_version: '2.3.*'
+ wpcs_version: 'dev-develop'
name: "QTest${{ matrix.phpcs_version == 'dev-master' && ' + Lint' || '' }}: PHP ${{ matrix.php }} - PHPCS ${{ matrix.phpcs_version }}"
@@ -54,24 +50,23 @@ jobs:
id: set_ini
run: |
if [[ "${{ matrix.phpcs_version }}" != "dev-master" ]]; then
- echo 'PHP_INI=error_reporting=E_ALL & ~E_DEPRECATED' >> $GITHUB_OUTPUT
- elif [[ "${{ matrix.php }}" == "latest" ]]; then
- echo 'PHP_INI=error_reporting=E_ALL & ~E_DEPRECATED' >> $GITHUB_OUTPUT
+ echo 'PHP_INI=error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On' >> $GITHUB_OUTPUT
else
- echo 'PHP_INI=error_reporting=-1' >> $GITHUB_OUTPUT
+ echo 'PHP_INI=error_reporting=-1, display_errors=On' >> $GITHUB_OUTPUT
fi
- - name: Install PHP
+ - name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
coverage: none
- - name: 'Composer: set PHPCS and WPCS versions for tests'
- run: |
- composer require --no-update --no-scripts squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-interaction
- composer require --no-update --no-scripts wp-coding-standards/wpcs:"${{ matrix.wpcs_version }}" --no-interaction
+ - name: 'Composer: set PHPCS version for tests'
+ run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction
+
+ - name: 'Composer: set WPCS version for tests'
+ run: composer require wp-coding-standards/wpcs:"${{ matrix.wpcs_version }}" --no-update --no-scripts --no-interaction
# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
@@ -91,6 +86,9 @@ jobs:
composer-options: --ignore-platform-reqs
custom-cache-suffix: $(date -u -d "-0 month -$(($(date +%d)-1)) days" "+%F")
+ - name: Display PHPCS installed standards
+ run: ./vendor/bin/phpcs -i
+
- name: Lint against parse errors
if: matrix.phpcs_version == 'dev-master'
run: ./bin/php-lint
diff --git a/.github/workflows/test.yml b/.github/workflows/unit-tests.yml
similarity index 59%
rename from .github/workflows/test.yml
rename to .github/workflows/unit-tests.yml
index 0e4cb6cf..926178e9 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/unit-tests.yml
@@ -1,4 +1,4 @@
-name: Test
+name: Unit Tests
on:
# Run on pushes to `master` and on all pull requests.
@@ -27,10 +27,10 @@ jobs:
strategy:
matrix:
- php: ['5.4', 'latest', '8.2']
+ php: ['5.4', 'latest', '8.3']
name: "Lint: PHP ${{ matrix.php }}"
- continue-on-error: ${{ matrix.php == '8.2' }}
+ continue-on-error: ${{ matrix.php == '8.3' }}
steps:
- name: Checkout code
@@ -46,8 +46,8 @@ jobs:
- name: Install Composer dependencies
uses: "ramsey/composer-install@v2"
with:
- # Bust the cache at least once a month - output format: YYYY-MM-DD.
- custom-cache-suffix: $(date -u -d "-0 month -$(($(date +%d)-1)) days" "+%F")
+ # Bust the cache at least once a month - output format: YYYY-MM.
+ custom-cache-suffix: $(date -u "+%Y-%m")
- name: Lint against parse errors
run: ./bin/php-lint --checkstyle | cs2pr
@@ -70,41 +70,19 @@ jobs:
# no additional versions are included in the array.
# - experimental: Whether the build is "allowed to fail".
matrix:
- php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
- phpcs_version: ['3.5.5', 'dev-master']
- wpcs_version: ['2.3.*']
+ php: ['5.4', '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
+ phpcs_version: ['3.7.1', 'dev-master']
+ wpcs_version: ['dev-develop']
experimental: [false]
include:
- # Complete the matrix by adding PHP 8.0, but only test against compatible PHPCS versions.
- - php: '8.0'
- phpcs_version: 'dev-master'
- wpcs_version: '2.3.*'
- experimental: false
- - php: '8.0'
- # PHPCS 3.5.7 is the lowest version of PHPCS which supports PHP 8.0.
- phpcs_version: '3.5.7'
- wpcs_version: '2.3.*'
- experimental: false
-
- # Complete the matrix by adding PHP 8.1, but only test against compatible PHPCS versions.
- - php: '8.1'
- phpcs_version: 'dev-master'
- wpcs_version: '2.3.*'
- experimental: false
- - php: '8.1'
- # PHPCS 3.6.1 is the lowest version of PHPCS which supports PHP 8.1.
- phpcs_version: '3.6.1'
- wpcs_version: '2.3.*'
- experimental: false
-
# Experimental builds. These are allowed to fail.
- #- php: '8.2'
- # phpcs_version: 'dev-master'
- # wpcs_version: '2.3.*'
- # experimental: true
+ - php: '8.3'
+ phpcs_version: 'dev-master'
+ wpcs_version: 'dev-develop'
+ experimental: true
- name: "Test: PHP ${{ matrix.php }} - PHPCS ${{ matrix.phpcs_version }} - WPCS ${{ matrix.wpcs_version }}"
+ name: "PHP ${{ matrix.php }} on PHPCS ${{ matrix.phpcs_version }}"
continue-on-error: ${{ matrix.experimental }}
@@ -119,49 +97,49 @@ jobs:
id: set_ini
run: |
if [[ "${{ matrix.phpcs_version }}" != "dev-master" ]]; then
- echo 'PHP_INI=error_reporting=E_ALL & ~E_DEPRECATED' >> $GITHUB_OUTPUT
- elif [[ "${{ matrix.php }}" == "8.1" ]]; then
- echo 'PHP_INI=error_reporting=E_ALL & ~E_DEPRECATED' >> $GITHUB_OUTPUT
+ echo 'PHP_INI=error_reporting=E_ALL & ~E_DEPRECATED, display_errors=On' >> $GITHUB_OUTPUT
else
- echo 'PHP_INI=error_reporting=-1' >> $GITHUB_OUTPUT
+ echo 'PHP_INI=error_reporting=-1, display_errors=On' >> $GITHUB_OUTPUT
fi
- - name: Install PHP
+ - name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
ini-values: ${{ steps.set_ini.outputs.PHP_INI }}
coverage: none
- - name: 'Composer: set PHPCS and WPCS versions for tests'
- run: |
- composer require --no-update --no-scripts squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-interaction
- composer require --no-update --no-scripts wp-coding-standards/wpcs:"${{ matrix.wpcs_version }}" --no-interaction
+ - name: 'Composer: set PHPCS version for tests'
+ run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction
+
+ - name: 'Composer: set WPCS version for tests'
+ run: composer require wp-coding-standards/wpcs:"${{ matrix.wpcs_version }}" --no-update --no-scripts --no-interaction
# 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"
+ - name: Install Composer dependencies (PHP < 8.0 )
+ if: ${{ matrix.php < 8.0 }}
+ uses: ramsey/composer-install@v2
with:
- # Bust the cache at least once a month - output format: YYYY-MM-DD.
- custom-cache-suffix: $(date -u -d "-0 month -$(($(date +%d)-1)) days" "+%F")
+ # 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"
+ - name: Install Composer dependencies (PHP >= 8.0)
+ if: ${{ matrix.php >= 8.0 }}
+ uses: ramsey/composer-install@v2
with:
composer-options: --ignore-platform-reqs
- custom-cache-suffix: $(date -u -d "-0 month -$(($(date +%d)-1)) days" "+%F")
+ custom-cache-suffix: $(date -u "+%Y-%m")
- - name: Run the unit tests - PHP 5.4 - 8.0
- if: matrix.php < '8.1'
+ # Simplify these next two down once bin/unit-tests.yml contains the condition (#735).
+ - name: Run the unit tests - PHP 5.4 — 8.0
+ if: ${{ matrix.php < '8.1' }}
run: ./bin/unit-tests
- - name: Run the unit tests - PHP > 8.1
- if: matrix.php >= '8.1'
+ - name: Run the unit tests - PHP >= 8.1
+ if: ${{ matrix.php >= '8.1' }}
run: vendor/bin/phpunit --filter WordPressVIPMinimum ./vendor/squizlabs/php_codesniffer/tests/AllTests.php --no-coverage --no-configuration --bootstrap=./tests/bootstrap.php --dont-report-useless-tests
- name: Run the ruleset tests
diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist
index 424f4095..a0049b7b 100644
--- a/.phpcs.xml.dist
+++ b/.phpcs.xml.dist
@@ -19,7 +19,7 @@
-
+
diff --git a/README.md b/README.md
index a52db246..f2049fbd 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ Go to https://docs.wpvip.com/technical-references/code-review/phpcs-report/ to l
## Minimal requirements
* PHP 5.4+
-* [PHPCS 3.5.5+](https://github.com/squizlabs/PHP_CodeSniffer/releases)
+* [PHPCS 3.7.1+](https://github.com/squizlabs/PHP_CodeSniffer/releases)
* [WPCS 2.3.0+](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/releases)
* [VariableAnalysis 2.11.1+](https://github.com/sirbrillig/phpcs-variable-analysis/releases)
diff --git a/WordPress-VIP-Go/ruleset-test.inc b/WordPress-VIP-Go/ruleset-test.inc
index 61e56955..c4037d25 100644
--- a/WordPress-VIP-Go/ruleset-test.inc
+++ b/WordPress-VIP-Go/ruleset-test.inc
@@ -165,7 +165,7 @@ rawurlencode(); // Ok.
extract( array( 'a' => 1 ) ); // Error.
$obj->extract(); // Ok.
-// WordPress.PHP.StrictComparisons.LooseComparison
+// Universal.Operators.StrictComparisons.LooseComparison
true == $true; // Warning.
false === $true; // Ok.
@@ -546,7 +546,7 @@ str_replace( 'foo', array( 'bar', 'foo' ), 'foobar' ); // Error.
// WordPressVIPMinimum.Security.Underscorejs
echo "";
diff --git a/WordPress-VIP-Go/ruleset.xml b/WordPress-VIP-Go/ruleset.xml
index 58386a58..7626cf76 100644
--- a/WordPress-VIP-Go/ruleset.xml
+++ b/WordPress-VIP-Go/ruleset.xml
@@ -109,7 +109,7 @@
This includes potential security holes as well as functions that may bring down sites for performance reasons.
-->
-
+
File system operations only work on the `/tmp/` and `wp-content/uploads/` directories. To avoid unexpected results, please use helper functions like `get_temp_dir()` or `wp_get_upload_dir()` to get the proper directory path when using functions such as %s(). For more details, please see: https://docs.wpvip.com/technical-references/vip-go-files-system/local-file-operations/
@@ -193,7 +193,7 @@
3
-
+
3
@@ -263,10 +263,10 @@
0
-
+
0
-
+
0
diff --git a/WordPressVIPMinimum/Sniffs/AbstractVariableRestrictionsSniff.php b/WordPressVIPMinimum/Sniffs/AbstractVariableRestrictionsSniff.php
index e46373a3..e9d4f731 100644
--- a/WordPressVIPMinimum/Sniffs/AbstractVariableRestrictionsSniff.php
+++ b/WordPressVIPMinimum/Sniffs/AbstractVariableRestrictionsSniff.php
@@ -9,7 +9,7 @@
namespace WordPressVIPMinimum\Sniffs;
-use WordPressVIPMinimum\Sniffs\Sniff;
+use PHPCSUtils\Utils\MessageHelper;
/**
* Restricts usage of some variables.
@@ -200,11 +200,13 @@ public function process_token( $stackPtr ) {
continue;
}
- $this->addMessage(
+ $code = MessageHelper::stringToErrorcode( $groupName . '_' . $match[1] );
+ MessageHelper::addMessage(
+ $this->phpcsFile,
$group['message'],
$stackPtr,
$group['type'] === 'error',
- $this->string_to_errorcode( $groupName . '_' . $match[1] ),
+ $code,
[ $var ]
);
diff --git a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php
index 6b294807..dea566e2 100644
--- a/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php
+++ b/WordPressVIPMinimum/Sniffs/Classes/DeclarationCompatibilitySniff.php
@@ -291,7 +291,7 @@ protected function processTokenWithinScope( File $phpcsFile, $stackPtr, $currSco
return;
}
}
- $i++;
+ ++$i;
}
}
diff --git a/WordPressVIPMinimum/Sniffs/Compatibility/ZoninatorSniff.php b/WordPressVIPMinimum/Sniffs/Compatibility/ZoninatorSniff.php
index 1dae2b96..b773c79b 100644
--- a/WordPressVIPMinimum/Sniffs/Compatibility/ZoninatorSniff.php
+++ b/WordPressVIPMinimum/Sniffs/Compatibility/ZoninatorSniff.php
@@ -80,11 +80,11 @@ public function process_token( $stackPtr ) {
/**
* Removes the quotation marks around T_CONSTANT_ENCAPSED_STRING.
*
- * @param string $string T_CONSTANT_ENCAPSED_STRING containing wrapping quotation marks.
+ * @param string $text_string T_CONSTANT_ENCAPSED_STRING containing wrapping quotation marks.
*
* @return string String w/o wrapping quotation marks.
*/
- public function remove_wrapping_quotation_marks( $string ) {
- return trim( str_replace( '"', "'", $string ), "'" );
+ public function remove_wrapping_quotation_marks( $text_string ) {
+ return trim( str_replace( '"', "'", $text_string ), "'" );
}
}
diff --git a/WordPressVIPMinimum/Sniffs/Constants/ConstantStringSniff.php b/WordPressVIPMinimum/Sniffs/Constants/ConstantStringSniff.php
index d6506c8f..9656d188 100644
--- a/WordPressVIPMinimum/Sniffs/Constants/ConstantStringSniff.php
+++ b/WordPressVIPMinimum/Sniffs/Constants/ConstantStringSniff.php
@@ -8,8 +8,9 @@
namespace WordPressVIPMinimum\Sniffs\Constants;
-use WordPressVIPMinimum\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;
+use PHPCSUtils\Utils\PassedParameters;
+use WordPressVIPMinimum\Sniffs\Sniff;
/**
* Sniff for properly using constant name when checking whether a constant is defined.
@@ -55,7 +56,7 @@ public function process_token( $stackPtr ) {
return;
}
- $param = $this->get_function_call_parameter( $stackPtr, 1 );
+ $param = PassedParameters::getParameter( $this->phpcsFile, $stackPtr, 1 );
if ( $param === false ) {
// Target parameter not found.
return;
diff --git a/WordPressVIPMinimum/Sniffs/Functions/DynamicCallsSniff.php b/WordPressVIPMinimum/Sniffs/Functions/DynamicCallsSniff.php
index c069696f..ca2f2acc 100644
--- a/WordPressVIPMinimum/Sniffs/Functions/DynamicCallsSniff.php
+++ b/WordPressVIPMinimum/Sniffs/Functions/DynamicCallsSniff.php
@@ -8,6 +8,7 @@
namespace WordPressVIPMinimum\Sniffs\Functions;
use PHP_CodeSniffer\Util\Tokens;
+use PHPCSUtils\Utils\TextStrings;
use WordPressVIPMinimum\Sniffs\Sniff;
/**
@@ -139,7 +140,7 @@ private function collect_variables() {
* If we reached the end of the loop and the $value_ptr was set, we know for sure
* this was a plain text string variable assignment.
*/
- $current_var_value = $this->strip_quotes( $this->tokens[ $value_ptr ]['content'] );
+ $current_var_value = TextStrings::stripQuotes( $this->tokens[ $value_ptr ]['content'] );
if ( isset( $this->disallowed_functions[ $current_var_value ] ) === false ) {
// Text string is not one of the ones we're looking for.
diff --git a/WordPressVIPMinimum/Sniffs/Hooks/AlwaysReturnInFilterSniff.php b/WordPressVIPMinimum/Sniffs/Hooks/AlwaysReturnInFilterSniff.php
index 8029e732..4c02d878 100644
--- a/WordPressVIPMinimum/Sniffs/Hooks/AlwaysReturnInFilterSniff.php
+++ b/WordPressVIPMinimum/Sniffs/Hooks/AlwaysReturnInFilterSniff.php
@@ -7,8 +7,9 @@
namespace WordPressVIPMinimum\Sniffs\Hooks;
-use WordPressVIPMinimum\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;
+use PHPCSUtils\Utils\Arrays;
+use WordPressVIPMinimum\Sniffs\Sniff;
/**
* This sniff validates that filters always return a value
@@ -94,7 +95,7 @@ public function process_token( $stackPtr ) {
*/
private function processArray( $stackPtr ) {
- $open_close = $this->find_array_open_close( $stackPtr );
+ $open_close = Arrays::getOpenClose( $this->phpcsFile, $stackPtr );
if ( $open_close === false ) {
return;
}
@@ -218,9 +219,9 @@ private function processFunctionBody( $stackPtr ) {
while ( $returnTokenPtr ) {
if ( $this->isInsideIfConditonal( $returnTokenPtr ) ) {
- $insideIfConditionalReturn++;
+ ++$insideIfConditionalReturn;
} else {
- $outsideConditionalReturn++;
+ ++$outsideConditionalReturn;
}
if ( $this->isReturningVoid( $returnTokenPtr ) ) {
$message = 'Please, make sure that a callback to `%s` filter is returning void intentionally.';
diff --git a/WordPressVIPMinimum/Sniffs/Hooks/PreGetPostsSniff.php b/WordPressVIPMinimum/Sniffs/Hooks/PreGetPostsSniff.php
index 75b54729..c34030c0 100644
--- a/WordPressVIPMinimum/Sniffs/Hooks/PreGetPostsSniff.php
+++ b/WordPressVIPMinimum/Sniffs/Hooks/PreGetPostsSniff.php
@@ -7,8 +7,9 @@
namespace WordPressVIPMinimum\Sniffs\Hooks;
-use WordPressVIPMinimum\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;
+use PHPCSUtils\Utils\Arrays;
+use WordPressVIPMinimum\Sniffs\Sniff;
/**
* This sniff validates a proper usage of pre_get_posts action callback.
@@ -95,7 +96,7 @@ public function process_token( $stackPtr ) {
*/
private function processArray( $stackPtr ) {
- $open_close = $this->find_array_open_close( $stackPtr );
+ $open_close = Arrays::getOpenClose( $this->phpcsFile, $stackPtr );
if ( $open_close === false ) {
return;
}
diff --git a/WordPressVIPMinimum/Sniffs/Performance/LowExpiryCacheTimeSniff.php b/WordPressVIPMinimum/Sniffs/Performance/LowExpiryCacheTimeSniff.php
index 23639560..d22716ad 100644
--- a/WordPressVIPMinimum/Sniffs/Performance/LowExpiryCacheTimeSniff.php
+++ b/WordPressVIPMinimum/Sniffs/Performance/LowExpiryCacheTimeSniff.php
@@ -8,6 +8,7 @@
namespace WordPressVIPMinimum\Sniffs\Performance;
use PHP_CodeSniffer\Util\Tokens;
+use PHPCSUtils\Utils\TextStrings;
use WordPressCS\WordPress\AbstractFunctionParameterSniff;
/**
@@ -147,7 +148,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
}
if ( $this->tokens[ $i ]['code'] === T_CONSTANT_ENCAPSED_STRING ) {
- $content = $this->strip_quotes( $this->tokens[ $i ]['content'] );
+ $content = TextStrings::stripQuotes( $this->tokens[ $i ]['content'] );
if ( is_numeric( $content ) === true ) {
$tokensAsString .= $content;
continue;
diff --git a/WordPressVIPMinimum/Sniffs/Security/ProperEscapingFunctionSniff.php b/WordPressVIPMinimum/Sniffs/Security/ProperEscapingFunctionSniff.php
index 9b9513f0..1e61b25b 100644
--- a/WordPressVIPMinimum/Sniffs/Security/ProperEscapingFunctionSniff.php
+++ b/WordPressVIPMinimum/Sniffs/Security/ProperEscapingFunctionSniff.php
@@ -8,8 +8,9 @@
namespace WordPressVIPMinimum\Sniffs\Security;
-use WordPressVIPMinimum\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;
+use PHPCSUtils\Utils\TextStrings;
+use WordPressVIPMinimum\Sniffs\Sniff;
/**
* Checks whether proper escaping function is used.
@@ -182,7 +183,7 @@ public function process_token( $stackPtr ) {
$content = $this->tokens[ $html ]['content'];
if ( isset( Tokens::$stringTokens[ $this->tokens[ $html ]['code'] ] ) === true ) {
- $content = Sniff::strip_quotes( $content );
+ $content = TextStrings::stripQuotes( $content );
}
$escaping_type = $this->escaping_functions[ $function_name ];
diff --git a/WordPressVIPMinimum/Sniffs/Security/UnderscorejsSniff.php b/WordPressVIPMinimum/Sniffs/Security/UnderscorejsSniff.php
index 6ea36135..0118184c 100644
--- a/WordPressVIPMinimum/Sniffs/Security/UnderscorejsSniff.php
+++ b/WordPressVIPMinimum/Sniffs/Security/UnderscorejsSniff.php
@@ -9,6 +9,7 @@
namespace WordPressVIPMinimum\Sniffs\Security;
use PHP_CodeSniffer\Util\Tokens;
+use PHPCSUtils\Utils\TextStrings;
use WordPressVIPMinimum\Sniffs\Sniff;
/**
@@ -72,7 +73,7 @@ public function process_token( $stackPtr ) {
/*
* Ignore Gruntfile.js files as they are configuration, not code.
*/
- $file_name = $this->strip_quotes( $this->phpcsFile->getFileName() );
+ $file_name = TextStrings::stripQuotes( $this->phpcsFile->getFileName() );
$file_name = strtolower( basename( $file_name ) );
if ( $file_name === 'gruntfile.js' ) {
@@ -120,7 +121,7 @@ public function process_token( $stackPtr ) {
return;
}
- $content = $this->strip_quotes( $this->tokens[ $stackPtr ]['content'] );
+ $content = TextStrings::stripQuotes( $this->tokens[ $stackPtr ]['content'] );
$match_count = preg_match_all( self::UNESCAPED_INTERPOLATE_REGEX, $content, $matches );
if ( $match_count > 0 ) {
diff --git a/WordPressVIPMinimum/Sniffs/Sniff.php b/WordPressVIPMinimum/Sniffs/Sniff.php
index dfad0381..68d8ea55 100644
--- a/WordPressVIPMinimum/Sniffs/Sniff.php
+++ b/WordPressVIPMinimum/Sniffs/Sniff.php
@@ -17,4 +17,45 @@
* @package VIPCS\WordPressVIPMinimum
*/
abstract class Sniff extends \WordPressCS\WordPress\Sniff {
+ /**
+ * Merge a pre-set array with a ruleset-provided array.
+ *
+ * - By default flips custom lists to allow for using `isset()` instead
+ * of `in_array()`.
+ * - When `$flip` is true:
+ * * Presumes the base array is in a `'value' => true` format.
+ * * Any custom items will be given the value `false` to be able to
+ * distinguish them from pre-set (base array) values.
+ * * Will filter previously added custom items out from the base array
+ * before merging/returning to allow for resetting to the base array.
+ *
+ * {@internal Function is static as it doesn't use any of the properties or others
+ * methods anyway.}
+ *
+ * @param array $custom Custom list as provided via a ruleset.
+ * @param array $base Optional. Base list. Defaults to an empty array.
+ * Expects `value => true` format when `$flip` is true.
+ * @param bool $flip Optional. Whether or not to flip the custom list.
+ * Defaults to true.
+ * @return array
+ */
+ public static function merge_custom_array( $custom, $base = [], $flip = true ) {
+ if ( $flip === true ) {
+ $base = array_filter( $base );
+ }
+
+ if ( empty( $custom ) || ! \is_array( $custom ) ) {
+ return $base;
+ }
+
+ if ( $flip === true ) {
+ $custom = array_fill_keys( $custom, false );
+ }
+
+ if ( empty( $base ) ) {
+ return $custom;
+ }
+
+ return array_merge( $base, $custom );
+ }
}
diff --git a/WordPressVIPMinimum/Sniffs/UserExperience/AdminBarRemovalSniff.php b/WordPressVIPMinimum/Sniffs/UserExperience/AdminBarRemovalSniff.php
index 6b985f07..094cd702 100644
--- a/WordPressVIPMinimum/Sniffs/UserExperience/AdminBarRemovalSniff.php
+++ b/WordPressVIPMinimum/Sniffs/UserExperience/AdminBarRemovalSniff.php
@@ -9,6 +9,7 @@
namespace WordPressVIPMinimum\Sniffs\UserExperience;
+use PHPCSUtils\Utils\TextStrings;
use WordPressCS\WordPress\AbstractFunctionParameterSniff;
use PHP_CodeSniffer\Util\Tokens;
@@ -207,13 +208,13 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
break;
case 'add_filter':
- $filter_name = $this->strip_quotes( $parameters[1]['raw'] );
+ $filter_name = TextStrings::stripQuotes( $parameters[1]['raw'] );
if ( $filter_name !== 'show_admin_bar' ) {
break;
}
$error = true;
- if ( $this->remove_only === true && isset( $parameters[2]['raw'] ) && $this->strip_quotes( $parameters[2]['raw'] ) === '__return_true' ) {
+ if ( $this->remove_only === true && isset( $parameters[2]['raw'] ) && TextStrings::stripQuotes( $parameters[2]['raw'] ) === '__return_true' ) {
$error = false;
}
break;
diff --git a/WordPressVIPMinimum/ruleset-test.inc b/WordPressVIPMinimum/ruleset-test.inc
index 803e890f..ead31c64 100644
--- a/WordPressVIPMinimum/ruleset-test.inc
+++ b/WordPressVIPMinimum/ruleset-test.inc
@@ -72,7 +72,7 @@ new WP_Query( array(
// WordPress.WP.GlobalVariablesOverride
$GLOBALS['wpdb'] = 'test'; // Error.
-// WordPress.PHP.StrictComparisons
+// Universal.Operators.StrictComparisons
if ( true == $true ) { // Warning.
}
@@ -555,7 +555,7 @@ str_replace( 'foo', array( 'bar', 'foo' ), 'foobar' ); // Error.
// WordPressVIPMinimum.Security.Underscorejs
echo "";
diff --git a/WordPressVIPMinimum/ruleset.xml b/WordPressVIPMinimum/ruleset.xml
index 2ce2511c..1e968ef9 100644
--- a/WordPressVIPMinimum/ruleset.xml
+++ b/WordPressVIPMinimum/ruleset.xml
@@ -26,7 +26,9 @@
-
+
+ warning
+
@@ -123,9 +125,31 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/composer.json b/composer.json
index bab249fe..b478495b 100644
--- a/composer.json
+++ b/composer.json
@@ -1,63 +1,77 @@
{
"name": "automattic/vipwpcs",
- "type": "phpcodesniffer-standard",
"description": "PHP_CodeSniffer rules (sniffs) to enforce WordPress VIP minimum coding conventions",
+ "license": "MIT",
+ "type": "phpcodesniffer-standard",
"keywords": [
"phpcs",
"static analysis",
"standards",
"WordPress"
],
- "license": "MIT",
"authors": [
{
"name": "Contributors",
"homepage": "https://github.com/Automattic/VIP-Coding-Standards/graphs/contributors"
}
],
+ "support": {
+ "issues": "https://github.com/Automattic/VIP-Coding-Standards/issues",
+ "wiki": "https://github.com/Automattic/VIP-Coding-Standards/wiki",
+ "source": "https://github.com/Automattic/VIP-Coding-Standards"
+ },
"require": {
"php": ">=5.4",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.1 || ^0.5 || ^0.6.2 || ^0.7",
+ "phpcsstandards/phpcsextra": "^1.0",
+ "phpcsstandards/phpcsutils": "^1.0",
"sirbrillig/phpcs-variable-analysis": "^2.11.1",
- "squizlabs/php_codesniffer": "^3.5.5",
- "wp-coding-standards/wpcs": "^2.3"
+ "squizlabs/php_codesniffer": "^3.7.1",
+ "wp-coding-standards/wpcs": "dev-develop"
},
"require-dev": {
- "php-parallel-lint/php-parallel-lint": "^1.3.2",
"php-parallel-lint/php-console-highlighter": "^1.0.0",
+ "php-parallel-lint/php-parallel-lint": "^1.3.2",
"phpcompatibility/php-compatibility": "^9",
"phpcsstandards/phpcsdevtools": "^1.0",
"phpunit/phpunit": "^4 || ^5 || ^6 || ^7"
},
+ "minimum-stability": "dev",
+ "prefer-stable": true,
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"scripts": {
- "install-codestandards": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run",
- "ruleset": "bin/ruleset-tests",
- "lint": [
- "bin/php-lint",
- "bin/xml-lint"
+ "check-all": [
+ "@lint",
+ "@check-cs",
+ "@run-tests",
+ "@run-ruleset-tests",
+ "@check-complete"
],
- "phpcs": "bin/phpcs",
- "phpunit": "bin/unit-tests",
- "coverage": "bin/unit-tests-coverage",
"check-complete": [
"@php ./vendor/phpcsstandards/phpcsdevtools/bin/phpcs-check-feature-completeness -q ./WordPressVIPMinimum"
],
- "test": [
- "@lint",
- "@ruleset",
- "@phpunit",
- "@phpcs",
- "@check-complete"
- ]
+ "check-complete-strict": [
+ "@php ./vendor/phpcsstandards/phpcsdevtools/bin/phpcs-check-feature-completeness ./WordPressVIPMinimum"
+ ],
+ "check-cs": "bin/phpcs",
+ "lint": [
+ "bin/php-lint",
+ "bin/xml-lint"
+ ],
+ "run-ruleset-tests": "bin/ruleset-tests",
+ "run-tests": "bin/unit-tests",
+ "run-tests-coverage": "bin/unit-tests-coverage"
},
- "support": {
- "issues": "https://github.com/Automattic/VIP-Coding-Standards/issues",
- "wiki": "https://github.com/Automattic/VIP-Coding-Standards/wiki",
- "source": "https://github.com/Automattic/VIP-Coding-Standards"
+ "scripts-descriptions": {
+ "check-all": "Run all checks (lint, phpcs, feature completeness) and tests.",
+ "check-complete": "Check if all the sniffs have tests.",
+ "check-complete-strict": "Check if all the sniffs have unit tests and XML documentation.",
+ "check-cs": "Run the PHPCS script against the entire codebase.",
+ "lint": "Lint PHP files against parse errors.",
+ "run-tests": "Run all the unit tests for the VIP Coding Standards sniffs."
}
}
diff --git a/tests/RulesetTest.php b/tests/RulesetTest.php
index d67a3454..0a9de437 100644
--- a/tests/RulesetTest.php
+++ b/tests/RulesetTest.php
@@ -98,6 +98,9 @@ public function __construct( $ruleset, $expected = [] ) {
$this->phpcs_bin = realpath( $phpcs_bin );
}
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
+ printf( 'Testing the ' . $this->ruleset . ' ruleset.' . PHP_EOL );
+
$output = $this->collect_phpcs_result();
if ( ! is_object( $output ) || empty( $output ) ) {
@@ -144,10 +147,11 @@ private function collect_phpcs_result() {
$shell = sprintf(
'%1$s%2$s --severity=1 --standard=%3$s --report=json ./%3$s/ruleset-test.inc',
- $php, // Current PHP executable if avaiable.
+ $php, // Current PHP executable if available.
$this->phpcs_bin,
$this->ruleset
);
+
// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_exec -- This is test code, not production.
$output = shell_exec( $shell );