Suggestion: Adopt WordPress PHP Coding Standards (#905)

* Update phpcs rules

* Automated style updates

* Silence all other Warnings and Errors

We'll fix them in follow ups.
This commit is contained in:
Konstantin Obenland 2024-09-28 12:53:21 -05:00 committed by GitHub
parent f5989f0380
commit 2b5f635ba3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
44 changed files with 441 additions and 446 deletions

View file

@ -41,7 +41,7 @@
"vendor/bin/phpunit"
],
"lint": [
"vendor/bin/phpcs -n -q"
"vendor/bin/phpcs"
],
"lint:fix": [
"vendor/bin/phpcbf"

View file

@ -51,6 +51,7 @@ class Event extends Base_Object {
/**
* Mobilizon compatible values for repliesModertaionOption.
*
* @var array
*/
const REPLIES_MODERATION_OPTION_TYPES = array( 'allow_all', 'closed' );
@ -62,6 +63,7 @@ class Event extends Base_Object {
/**
* Allowed values for ical VEVENT STATUS.
*
* @var array
*/
const ICAL_EVENT_STATUS_TYPES = array( 'TENTATIVE', 'CONFIRMED', 'CANCELLED' );
@ -70,6 +72,7 @@ class Event extends Base_Object {
* Default event categories.
*
* These values currently reflect the default set as proposed by Mobilizon to maximize interoperability.
*
* @var array
*/
const DEFAULT_EVENT_CATEGORIES = array(

View file

@ -152,6 +152,7 @@ class Blocks {
/**
* Filter an array by a list of keys.
*
* @param array $array The array to filter.
* @param array $keys The keys to keep.
* @return array The filtered array.
@ -162,6 +163,7 @@ class Blocks {
/**
* Render the follow me block.
*
* @param array $attrs The block attributes.
* @return string The HTML to render.
*/

View file

@ -496,7 +496,7 @@ class Comment {
\wp_enqueue_style(
$handle,
\plugins_url( 'build/remote-reply/style-index.css', __DIR__ ),
[ 'wp-components' ],
array( 'wp-components' ),
$assets['version']
);
}

View file

@ -28,7 +28,8 @@ class Hashtag {
* @return array the activity object array
*/
public static function filter_activity_object( $object_array ) {
/* Removed until this is merged: https://github.com/mastodon/mastodon/pull/28629
/*
Removed until this is merged: https://github.com/mastodon/mastodon/pull/28629
if ( ! empty( $object_array['summary'] ) ) {
$object_array['summary'] = self::the_content( $object_array['summary'] );
}

View file

@ -24,7 +24,8 @@ class Link {
* @return array the activity object array
*/
public static function filter_activity_object( $object_array ) {
/* Removed until this is merged: https://github.com/mastodon/mastodon/pull/28629
/*
Removed until this is merged: https://github.com/mastodon/mastodon/pull/28629
if ( ! empty( $object_array['summary'] ) ) {
$object_array['summary'] = self::the_content( $object_array['summary'] );
}

View file

@ -359,7 +359,7 @@ class Signature {
if ( $signature_block['algorithm'] ) {
switch ( $signature_block['algorithm'] ) {
case 'rsa-sha-512':
return 'sha512'; //hs2019 https://datatracker.ietf.org/doc/html/draft-cavage-http-signatures-12
return 'sha512'; // hs2019 https://datatracker.ietf.org/doc/html/draft-cavage-http-signatures-12
default:
return 'sha256';
}

View file

@ -247,6 +247,7 @@ class Extra_Fields {
/**
* Checks if the user is the blog user.
*
* @param int $user_id The user ID.
* @return bool True if the user is the blog user, otherwise false.
*/

View file

@ -62,7 +62,7 @@ class Interactions {
public static function update_comment( $activity ) {
$meta = get_remote_metadata_by_actor( $activity['actor'] );
//Determine comment_ID
// Determine comment_ID
$comment = object_id_to_comment( \esc_url_raw( $activity['object']['id'] ) );
$commentdata = \get_comment( $comment, ARRAY_A );
@ -70,7 +70,7 @@ class Interactions {
return false;
}
//found a local comment id
// found a local comment id
$commentdata['comment_author'] = \esc_attr( $meta['name'] ? $meta['name'] : $meta['preferredUsername'] );
$commentdata['comment_content'] = \addslashes( $activity['object']['content'] );

View file

@ -64,7 +64,10 @@ function get_remote_metadata_by_actor( $actor, $cached = true ) {
return new WP_Error(
'activitypub_no_valid_actor_identifier',
\__( 'The "actor" identifier is not valid', 'activitypub' ),
array( 'status' => 404, 'actor' => $actor )
array(
'status' => 404,
'actor' => $actor,
)
);
}
}
@ -77,7 +80,10 @@ function get_remote_metadata_by_actor( $actor, $cached = true ) {
return new WP_Error(
'activitypub_no_valid_actor_identifier',
\__( 'The "actor" identifier is not valid', 'activitypub' ),
array( 'status' => 404, 'actor' => $actor )
array(
'status' => 404,
'actor' => $actor,
)
);
}
@ -100,7 +106,10 @@ function get_remote_metadata_by_actor( $actor, $cached = true ) {
$metadata = new WP_Error(
'activitypub_no_valid_actor_url',
\__( 'The "actor" is no valid URL', 'activitypub' ),
array( 'status' => 400, 'actor' => $actor )
array(
'status' => 400,
'actor' => $actor,
)
);
return $metadata;
}
@ -118,7 +127,10 @@ function get_remote_metadata_by_actor( $actor, $cached = true ) {
$metadata = new WP_Error(
'activitypub_invalid_json',
\__( 'No valid JSON data', 'activitypub' ),
array( 'status' => 400, 'actor' => $actor )
array(
'status' => 400,
'actor' => $actor,
)
);
return $metadata;
}
@ -1019,7 +1031,6 @@ function custom_large_numbers( $formatted, $number, $decimals ) {
/**
* Registers a ActivityPub comment type.
*
*
* @param string $comment_type Key for comment type.
* @param array $args Arguments.
*
@ -1040,7 +1051,6 @@ function register_comment_type( $comment_type, $args = array() ) {
/**
* Fires after a ActivityPub comment type is registered.
*
*
* @param string $comment_type Comment type.
* @param array $args Arguments used to register the comment type.
*/
@ -1210,7 +1220,8 @@ function generate_post_summary( $post, $length = 500 ) {
$content = $content[0] . ' ' . $excerpt_more;
}
/* Removed until this is merged: https://github.com/mastodon/mastodon/pull/28629
/*
Removed until this is merged: https://github.com/mastodon/mastodon/pull/28629
return \apply_filters( 'the_excerpt', $content );
*/
return $content;

View file

@ -205,6 +205,7 @@ class Follower extends Actor {
* Beware that this os deleting a Follower for ALL users!!!
*
* To delete only the User connection (unfollow)
*
* @see \Activitypub\Rest\Followers::remove_follower()
*
* @return void

View file

@ -295,7 +295,10 @@ class User extends Actor {
* @return bool True if the attribute was updated, false otherwise.
*/
public function update_name( $value ) {
$userdata = [ 'ID' => $this->_id, 'display_name' => $value ];
$userdata = array(
'ID' => $this->_id,
'display_name' => $value,
);
return \wp_update_user( $userdata );
}

View file

@ -127,7 +127,10 @@ class Actors {
$url = str_replace( '{uri}', $resource, $template );
return new WP_REST_Response(
array( 'url' => $url, 'template' => $template ),
array(
'url' => $url,
'template' => $template,
),
200
);
}

View file

@ -84,7 +84,10 @@ class Comment {
$url = str_replace( '{uri}', $resource, $template );
return new WP_REST_Response(
array( 'url' => $url, 'template' => $template ),
array(
'url' => $url,
'template' => $template,
),
200
);
}

View file

@ -306,6 +306,7 @@ class Post extends Base {
/**
* Recursively get media IDs from blocks.
*
* @param array $blocks The blocks to search for media IDs
* @param array $media The media IDs to append new IDs to
* @param int $max_media The maximum number of media to return.

View file

@ -15,7 +15,7 @@ class Buddypress {
}
public static function add_user_metadata( $object, $author_id ) {
$object->url = bp_core_get_user_domain( $author_id ); //add BP member profile URL as user URL
$object->url = bp_core_get_user_domain( $author_id ); // add BP member profile URL as user URL
// add BuddyPress' cover_image instead of WordPress' header_image
$cover_image_url = bp_attachments_get_attachment( 'url', array( 'item_id' => $author_id ) );
@ -45,7 +45,7 @@ class Buddypress {
// replace blog URL on multisite
if ( is_multisite() ) {
$user_blogs = get_blogs_of_user( $author_id ); //get sites of user to send as AP metadata
$user_blogs = get_blogs_of_user( $author_id ); // get sites of user to send as AP metadata
if ( ! empty( $user_blogs ) ) {
unset( $object->attachment['blog_url'] );

View file

@ -11,11 +11,11 @@ class Jetpack {
if ( ! is_array( $whitelist ) ) {
return $whitelist;
}
$activitypub_meta_keys = [
$activitypub_meta_keys = array(
'activitypub_user_id',
'activitypub_inbox',
'activitypub_actor_json',
];
);
return \array_merge( $whitelist, $activitypub_meta_keys );
}
}

View file

@ -25,7 +25,7 @@ class Nodeinfo {
* Extend NodeInfo data
*
* @param array $nodeinfo NodeInfo data
* @param string The NodeInfo Version
* @param string $version The NodeInfo Version
*
* @return array The extended array
*/

View file

@ -5,74 +5,39 @@
<file>./includes/</file>
<file>./integration/</file>
<file>./build/</file>
<exclude-pattern>*\.(inc|css|js|svg)</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*.asset.php</exclude-pattern>
<arg value="ps"/>
<arg name="basepath" value="."/><!-- Strip the file paths down to the relevant bit -->
<arg name="colors"/>
<arg name="parallel" value="50"/>
<rule ref="PHPCompatibility"/>
<config name="testVersion" value="7.0-"/>
<rule ref="PHPCompatibilityWP"/>
<config name="minimum_supported_wp_version" value="4.7"/>
<rule ref="WordPress-Core">
<exclude name="Generic.Formatting.MultipleStatementAlignment.NotSameWarning" />
<exclude name="WordPress.Arrays.MultipleStatementAlignment.DoubleArrowNotAligned" />
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.SpaceAfterFunction" />
</rule>
<rule ref="WordPress.Files.FileName">
<properties>
<property name="strict_class_file_names" value="false" />
</properties>
</rule>
<rule ref="WordPress.WP.DeprecatedFunctions" />
<rule ref="WordPress-Extra" />
<rule ref="WordPress.WP.I18n"/>
<config name="text_domain" value="activitypub,default"/>
<arg value="ps"/>
<arg name="parallel" value="20"/>
<rule ref="VariableAnalysis"/>
<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable">
<type>error</type>
<rule ref="WordPress">
<exclude name="Generic.Commenting.DocComment.MissingShort"/>
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter"/>
<exclude name="Generic.Commenting.DocComment.LongNotCapital"/>
<exclude name="Squiz.Commenting"/>
<exclude name="Squiz.PHP.CommentedOutCode.Found"/>
<exclude name="Universal.NamingConventions.NoReservedKeywordParameterNames"/>
<exclude name="WordPress.Security.NonceVerification.Recommended"/>
<exclude name="WordPress.WP.GetMetaSingle.Missing"/>
<exclude name="WordPress.DB.PreparedSQL.NotPrepared"/>
</rule>
<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis">
<properties>
<property name="allowUnusedCaughtExceptions" value="true"/>
</properties>
</rule>
<rule ref="WordPress"/>
<rule ref="WordPress.WP.I18n.NoHtmlWrappedStrings">
<type>error</type>
</rule>
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
<rule ref="Generic.Arrays.DisallowShortArraySyntax">
<severity>0</severity>
</rule>
<rule ref="Universal.Arrays.DisallowShortArraySyntax">
<severity>0</severity>
</rule>
<rule ref="Squiz.Commenting">
<severity>0</severity>
</rule>
<rule ref="Generic.Commenting">
<severity>0</severity>
</rule>
<rule ref="WordPress.Files.FileName">
<severity>0</severity>
</rule>
<rule ref="WordPress.DB.PreparedSQL.NotPrepared">
<severity>0</severity>
</rule>
<rule ref="WordPress.WP.CapitalPDangit">
<severity>0</severity>
</rule>
<rule ref="WordPress.Arrays.ArrayDeclarationSpacing.AssociativeArrayFound">
<severity>0</severity>
</rule>
<rule ref="WordPress.PHP.YodaConditions.NotYoda">
<type>warning</type>
</rule>
<rule ref="WordPress.Arrays.ArrayDeclarationSpacing">
<exclude-pattern>**/*.asset.php</exclude-pattern>
<rule ref="VariableAnalysis">
<exclude name="VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable"/>
</rule>
<rule ref="WordPress.WP.Capabilities">
<properties>
<property name="custom_capabilities" type="array">