Skip to content

Commit

Permalink
Merge pull request #832 from WordPress/feature/update-to-wpcs-3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
schlessera authored Oct 9, 2023
2 parents 7661070 + 7f933f2 commit 2e79d09
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: 'latest'
coverage: none
tools: cs2pr

Expand Down
18 changes: 9 additions & 9 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@
<!-- Replaced by the Squiz version of the sniff which doesn't enforce whitespace around array index keys. -->
<exclude name="WordPress.Arrays.ArrayKeySpacingRestrictions"/>

<!-- Disabled as the preference for this repo is no spaces on the inside of parentheses.
Once WPCS 3.0.0 comes out, the opposite can be enforced via the
NormalizedArrays.Arrays.ArrayBraceSpacing sniff from PHPCSExtra. -->
<exclude name="WordPress.Arrays.ArrayDeclarationSpacing.NoSpaceAfterArrayOpener"/>
<exclude name="WordPress.Arrays.ArrayDeclarationSpacing.NoSpaceBeforeArrayCloser"/>

<!-- Let spacing before a cast be determined by the operator/parentheses whitespace rule
of the preceding character. -->
<exclude name="WordPress.WhiteSpace.CastStructureSpacing"/>
Expand All @@ -86,7 +80,7 @@
========================================================================== -->
<exclude name="WordPress.PHP.YodaConditions"/>
<!-- A while loop is the only valid control structure where an assignment can be justified. -->
<exclude name="WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition"/>
<exclude name="Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition"/>

<!-- ==========================================================================
Miscellaneous other exclusions.
Expand All @@ -96,7 +90,7 @@
<exclude name="WordPress.Files.FileName"/>

<!-- WPCS demands long arrays. We'll be using short arrays from now on. -->
<exclude name="Generic.Arrays.DisallowShortArraySyntax"/>
<exclude name="Universal.Arrays.DisallowShortArraySyntax"/>

<!-- Ignore WP specific sniffs as Requests is also used outside of a WP context. -->
<exclude name="WordPress.WP"/>
Expand Down Expand Up @@ -133,6 +127,12 @@
</properties>
</rule>

<rule ref="NormalizedArrays.Arrays.ArrayBraceSpacing">
<properties>
<property name="spacesSingleLine" value="0"/>
</properties>
</rule>

<!-- Include replacement sniffs which enforce the opposite of WPCS for several excluded sniffs. -->
<rule ref="Squiz.WhiteSpace.ControlStructureSpacing">
<exclude name="Squiz.WhiteSpace.ControlStructureSpacing.LineAfterClose"/>
Expand Down Expand Up @@ -173,7 +173,7 @@
<!-- Allow error silencing only for a select group of functions. -->
<rule ref="WordPress.PHP.NoSilencedErrors">
<properties>
<property name="custom_whitelist" type="array">
<property name="customAllowedFunctionsList" type="array">
<element value="gzdecode"/>
<element value="gzinflate"/>
<element value="gzuncompress"/>
Expand Down
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,12 @@
"ext-json": "*"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"php-parallel-lint/php-console-highlighter": "^1.0.0",
"php-parallel-lint/php-parallel-lint": "^1.3.2",
"phpcompatibility/php-compatibility": "^9.0",
"requests/test-server": "dev-main",
"roave/security-advisories": "dev-latest",
"squizlabs/php_codesniffer": "^3.7.1",
"wp-coding-standards/wpcs": "^2.0",
"wp-coding-standards/wpcs": "^3.0",
"yoast/phpunit-polyfills": "^2.0.0"
},
"suggest": {
Expand Down
2 changes: 2 additions & 0 deletions library/Requests.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class Requests extends WpOrg\Requests\Requests {
*
* @codeCoverageIgnore
*
* @phpcs:disable Universal.NamingConventions.NoReservedKeywordParameterNames.classFound -- Deprecated, so not relevant to change.
*
* @param string $class Class name to load
*/
public static function autoloader($class) {
Expand Down
8 changes: 7 additions & 1 deletion src/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,13 @@ public function patch($url, $headers, $data = [], $options = []) {
* @throws \WpOrg\Requests\Exception On invalid URLs (`nonhttp`)
*/
public function request($url, $headers = [], $data = [], $type = Requests::GET, $options = []) {
$request = $this->merge_request(compact('url', 'headers', 'data', 'options'));
$request = [
'url' => $url,
'headers' => $headers,
'data' => $data,
'options' => $options,
];
$request = $this->merge_request($request);

return Requests::request($request['url'], $request['headers'], $request['data'], $type, $request['options']);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Autoload/AutoloadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ static function ($errno, $errstr) {
public function testAutoloadOfOldRequestsClassDoesNotThrowAFatalForFinalClass() {
define('REQUESTS_SILENCE_PSR0_DEPRECATIONS', true);

$this->assertInstanceOf(FilteredIterator::class, new Requests_utility_filteredIterator([], static function() {}));
$this->assertInstanceOf(FilteredIterator::class, new Requests_utility_filteredIterator([], static function () {}));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Cookie/ConstructorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ public function testAttributesAreNormalizedInDictionary() {
*
* @return array
*/
private function arrayUnshiftAssoc($base_array, $key, $value ) {
private function arrayUnshiftAssoc($base_array, $key, $value) {
$base_array = array_reverse($base_array, true);
$base_array[$key] = $value;
return array_reverse($base_array, true);
Expand Down
14 changes: 7 additions & 7 deletions tests/Hooks/DispatchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,48 +120,48 @@ public function testDispatchRespectsHookPriority() {
// Register multiple callbacks for the same hook with a variation of priorities.
$this->hooks->register(
'hook_a',
static function(&$text) {
static function (&$text) {
$text .= "no prio 0\n";
}
);
$this->hooks->register(
'hook_a',
static function(&$text) {
static function (&$text) {
$text .= "prio 10-1\n";
},
10
);
$this->hooks->register(
'hook_a',
static function(&$text) {
static function (&$text) {
$text .= "prio -3\n";
},
-3
);
$this->hooks->register(
'hook_a',
static function(&$text) {
static function (&$text) {
$text .= "prio 5\n";
},
5
);
$this->hooks->register(
'hook_a',
static function(&$text) {
static function (&$text) {
$text .= "prio 2-1\n";
},
2
);
$this->hooks->register(
'hook_a',
static function(&$text) {
static function (&$text) {
$text .= "prio 2-2\n";
},
2
);
$this->hooks->register(
'hook_a',
static function(&$text) {
static function (&$text) {
$text .= "prio 10-2\n";
},
10
Expand Down
2 changes: 1 addition & 1 deletion tests/Hooks/RegisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function testRegister() {
public function testRegisterClosureCallback() {
$this->hooks->register(
'hookname',
static function($param) {
static function () {
return true;
}
);
Expand Down

0 comments on commit 2e79d09

Please sign in to comment.