Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@
</properties>
</rule>

<rule ref="WordPress.WP.Capabilities">
<properties>
<property name="custom_capabilities" type="array">
<element value="jetpack_activate_modules" />
<element value="jetpack_admin_page" />
<element value="jetpack_configure_modules" />
<element value="jetpack_connect" />
<element value="jetpack_connect_user" />
<element value="jetpack_deactivate_modules" />
<element value="jetpack_disconnect" />
<element value="jetpack_manage_modules" />
<element value="jetpack_network_admin_page" />
<element value="jetpack_network_settings_page" />
<element value="jetpack_network_sites_page" />
<element value="jetpack_reconnect" />
<element value="view_stats" />
</property>
</properties>
</rule>

<!-- WordPress-Extra pulls this in. But PHP linting can be run more efficiently via bin/parallel-lint.sh than by having phpcs shell out to `php -l`. -->
<rule ref="Generic.PHP.Syntax">
<exclude name="Generic.PHP.Syntax" />
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"php-parallel-lint/php-parallel-lint": "1.3.2",
"sirbrillig/phpcs-changed": "2.10.0",
"squizlabs/php_codesniffer": "^3.6.2",
"wp-coding-standards/wpcs": "2022-02-07 as 2.3.1"
"wp-coding-standards/wpcs": "2023-01-04 as 2.3.1"
},
"scripts": {
"php:lint": [
Expand Down
70 changes: 34 additions & 36 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions projects/packages/autoloader/changelog/update-wpcs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: PHPCS fixes for new WPCS sniffs. Should be no user-visible changes.


2 changes: 2 additions & 0 deletions projects/packages/autoloader/tests/php/lib/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* @package automattic/jetpack-autoloader
*/

// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed

/**
* Since PHP8 added a warning for setting `$throw` to `false` in `spl_autoload_register()`,
* we need to define the autoload functions in order for them to be registered.
Expand Down
11 changes: 10 additions & 1 deletion projects/packages/codesniffer/Jetpack/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
<rule ref="MediaWiki.PHPUnit.AssertEquals" />
<rule ref="MediaWiki.PHPUnit.AssertionOrder" />
<rule ref="MediaWiki.PHPUnit.SpecificAssertions" />
<rule ref="MediaWiki.Usage.DirUsage" />
<rule ref="MediaWiki.Usage.DoubleNotOperator" />
<rule ref="MediaWiki.Usage.InArrayUsage" />
<rule ref="MediaWiki.Usage.MagicConstantClosure" />
Expand All @@ -41,6 +40,11 @@
<exclude name="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines" />
</rule>

<!-- Redundant to VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable, which checks more locations. -->
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter">
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter" />
</rule>

<!-- Only include select VIP rules -->
<rule ref="WordPressVIPMinimum.Files.IncludingFile.NotAbsolutePath" />

Expand Down Expand Up @@ -75,4 +79,9 @@
<exclude name="WordPress.WP.CapitalPDangit" />
</rule>

<!-- Not useful until we can use PHP 8's named parameters. We're currently stuck on 5.6! -->
<rule ref="Universal.NamingConventions.NoReservedKeywordParameterNames">
<exclude name="Universal.NamingConventions.NoReservedKeywordParameterNames" />
</rule>

</ruleset>
4 changes: 4 additions & 0 deletions projects/packages/codesniffer/changelog/update-wpcs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Updated to a newer snapshot of WordPress-Coding-Standards, which adds a number of new sniffs.
4 changes: 1 addition & 3 deletions projects/packages/codesniffer/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
},
"require-dev": {
"automattic/jetpack-changelogger": "@dev",
"wp-coding-standards/wpcs": "2022-02-07 as 2.3.1",
"phpcsstandards/phpcsutils": "1.0.0-alpha3",
"phpcsstandards/phpcsextra": "1.0.0-alpha3",
"wp-coding-standards/wpcs": "2023-01-04 as 2.3.1",
"yoast/phpunit-polyfills": "1.0.4"
},
"autoload": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ class Dummy_Class {
require_once 'bar.php';
$u->clone = clone $x;

// MediaWiki.Usage.DirUsage.
$u->dir = __DIR__;

// MediaWiki.Usage.DoubleNotOperator.
$u->bool = (bool) $u->bool;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
41 | ERROR | [ ] Absolute include path must be used. Use `get_template_directory()`, `get_stylesheet_directory()` or `plugin_dir_path()`.
| | (WordPressVIPMinimum.Files.IncludingFile.NotAbsolutePath)
42 | WARNING | [x] clone keyword must not be used as a function. (MediaWiki.ExtraCharacters.ParenthesesAroundKeyword.ParenthesesAroundKeywords)
45 | ERROR | [x] Use __DIR__ constant instead of calling dirname(__FILE__) (MediaWiki.Usage.DirUsage.FunctionFound)
48 | WARNING | [x] Use (bool) instead of !! (MediaWiki.Usage.DoubleNotOperator.DoubleNotOperator)
52 | ERROR | [ ] Found slow in_array( …, array_keys() ), should be array_key_exists() or isset() (MediaWiki.Usage.InArrayUsage.Found)
53 | ERROR | [ ] Found slow in_array( …, array_flip() ), should be array_key_exists() or isset() (MediaWiki.Usage.InArrayUsage.Found)
60 | WARNING | [ ] Avoid use of __METHOD__ magic constant in closure (MediaWiki.Usage.MagicConstantClosure.FoundConstantMethod)
60 | WARNING | [ ] Avoid use of __FUNCTION__ magic constant in closure (MediaWiki.Usage.MagicConstantClosure.FoundConstantFunction)
66 | ERROR | [ ] Function nested is nested inside of another function or closure (MediaWiki.Usage.NestedFunctions.NestedFunction)
70 | ERROR | [ ] Use "." for string concat (MediaWiki.Usage.PlusStringConcat.Found)
71 | ERROR | [ ] Use ".=" for string concat (MediaWiki.Usage.PlusStringConcat.Found)
74 | ERROR | [ ] The ampersand in "&$this" must be removed. If you plan to get back another instance of this class, assign $this to a temporary variable. (MediaWiki.Usage.ReferenceThis.Found)
77 | ERROR | [x] Multiple empty lines should not exist in a row; found 2 consecutive empty lines (MediaWiki.WhiteSpace.MultipleEmptyLines.MultipleEmptyLines)
80 | ERROR | [x] A single space should be after the function keyword in closures (MediaWiki.WhiteSpace.SpaceAfterClosure.NoWhitespaceAfterClosure)
87 | ERROR | [x] Multiple empty lines should not exist in a row; found 2 consecutive empty lines (MediaWiki.WhiteSpace.MultipleEmptyLines.MultipleEmptyLines)
45 | WARNING | [x] Use (bool) instead of !! (MediaWiki.Usage.DoubleNotOperator.DoubleNotOperator)
49 | ERROR | [ ] Found slow in_array( …, array_keys() ), should be array_key_exists() or isset() (MediaWiki.Usage.InArrayUsage.Found)
50 | ERROR | [ ] Found slow in_array( …, array_flip() ), should be array_key_exists() or isset() (MediaWiki.Usage.InArrayUsage.Found)
57 | WARNING | [ ] Avoid use of __METHOD__ magic constant in closure (MediaWiki.Usage.MagicConstantClosure.FoundConstantMethod)
57 | WARNING | [ ] Avoid use of __FUNCTION__ magic constant in closure (MediaWiki.Usage.MagicConstantClosure.FoundConstantFunction)
63 | ERROR | [ ] Function nested is nested inside of another function or closure (MediaWiki.Usage.NestedFunctions.NestedFunction)
67 | ERROR | [ ] Use "." for string concat (MediaWiki.Usage.PlusStringConcat.Found)
68 | ERROR | [ ] Use ".=" for string concat (MediaWiki.Usage.PlusStringConcat.Found)
71 | ERROR | [ ] The ampersand in "&$this" must be removed. If you plan to get back another instance of this class, assign $this to a temporary variable. (MediaWiki.Usage.ReferenceThis.Found)
74 | ERROR | [x] Multiple empty lines should not exist in a row; found 2 consecutive empty lines (MediaWiki.WhiteSpace.MultipleEmptyLines.MultipleEmptyLines)
77 | ERROR | [x] A single space should be after the function keyword in closures (MediaWiki.WhiteSpace.SpaceAfterClosure.NoWhitespaceAfterClosure)
84 | ERROR | [x] Multiple empty lines should not exist in a row; found 2 consecutive empty lines (MediaWiki.WhiteSpace.MultipleEmptyLines.MultipleEmptyLines)
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ class Dummy_Class {
require_once( 'bar.php' );
$u->clone = clone( $x );

// MediaWiki.Usage.DirUsage.
$u->dir = dirname( __FILE__ );

// MediaWiki.Usage.DoubleNotOperator.
$u->bool = ! ! $u->bool;

Expand Down
5 changes: 5 additions & 0 deletions projects/packages/connection/changelog/update-wpcs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: PHPCS fixes for new WPCS sniffs. Should be no user-visible changes.


3 changes: 2 additions & 1 deletion projects/packages/connection/src/class-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,8 @@ public function unlink_user_from_wpcom( $user_id ) {
* @return true|WP_Error True if owner successfully changed, WP_Error otherwise.
*/
public function update_connection_owner( $new_owner_id ) {
if ( ! user_can( $new_owner_id, 'administrator' ) ) {
$roles = new Roles();
if ( ! user_can( $new_owner_id, $roles->translate_role_to_cap( 'administrator' ) ) ) {
return new WP_Error(
'new_owner_not_admin',
__( 'New owner is not admin', 'jetpack-connection' ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public function get_access_token_data_provider() {
'no_possible_tokens', // expected error code.
false, // expected token.
),
'no tokens' => array(
'no tokens, has user_id' => array(
false, // blog token.
false, // user tokens.
false, // master_user.
Expand Down
5 changes: 5 additions & 0 deletions projects/packages/publicize/changelog/update-wpcs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: PHPCS fixes for new WPCS sniffs. Should be no user-visible changes.


2 changes: 2 additions & 0 deletions projects/packages/publicize/src/class-publicize-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,8 @@ public function has_paid_plan( $refresh_from_wpcom = false ) {
}
}

// phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move these functions to some other file.

/**
* Get Calypso URL for Publicize connections.
*
Expand Down
5 changes: 5 additions & 0 deletions projects/packages/roles/changelog/update-wpcs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: fixed
Comment: PHPCS fixes for new WPCS sniffs. Should be no user-visible changes.


2 changes: 2 additions & 0 deletions projects/packages/roles/tests/php/test-roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ function ( $cap ) {
);

$this->assertTrue( current_user_can( 'edit_others_posts' ) );
// phpcs:ignore WordPress.WP.Capabilities.Unknown
$this->assertFalse( current_user_can( 'foobar' ) );
// phpcs:ignore WordPress.WP.Capabilities.RoleFound
$this->assertFalse( current_user_can( 'administrator' ) );

$this->assertEquals( 'editor', $this->roles->translate_current_user_to_role() );
Expand Down
Loading