Skip to content

Commit ef66677

Browse files
obenlandpfefferle
andauthored
PHPCS: Include all files by default (#930)
* PHPCS: Include all files by default * simplify menu highlighting * Update includes/transformer/class-factory.php Co-authored-by: Matthias Pfefferle <[email protected]> --------- Co-authored-by: Matthias Pfefferle <[email protected]>
1 parent f8cd515 commit ef66677

25 files changed

+250
-164
lines changed

includes/class-notification.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ class Notification {
4242
/**
4343
* Notification constructor.
4444
*
45-
* @param string $type The type of the notification.
46-
* @param string $actor The actor URL.
47-
* @param array $object The Activity object.
48-
* @param int $target The WordPress User-Id.
45+
* @param string $type The type of the notification.
46+
* @param string $actor The actor URL.
47+
* @param array $activity The Activity object.
48+
* @param int $target The WordPress User-Id.
4949
*/
50-
public function __construct( $type, $actor, $object, $target ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound
50+
public function __construct( $type, $actor, $activity, $target ) {
5151
$this->type = $type;
5252
$this->actor = $actor;
53-
$this->object = $object;
53+
$this->object = $activity;
5454
$this->target = $target;
5555
}
5656

includes/class-signature.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public static function generate_signature( $user_id, $http_method, $url, $date,
221221

222222
$signature = null;
223223
\openssl_sign( $signed_string, $signature, $key, \OPENSSL_ALGO_SHA256 );
224-
$signature = \base64_encode( $signature ); // phpcs:ignore
224+
$signature = \base64_encode( $signature ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
225225

226226
$key_id = $user->get_url() . '#main-key';
227227

@@ -345,7 +345,7 @@ public static function get_remote_key( $key_id ) {
345345
);
346346
}
347347
if ( isset( $actor['publicKey']['publicKeyPem'] ) ) {
348-
return \rtrim( $actor['publicKey']['publicKeyPem'] ); // phpcs:ignore
348+
return \rtrim( $actor['publicKey']['publicKeyPem'] );
349349
}
350350
return new WP_Error(
351351
'activitypub_no_remote_key_found',
@@ -400,7 +400,7 @@ public static function parse_signature_header( $signature ) {
400400
$parsed_header['headers'] = \explode( ' ', trim( $matches[1] ) );
401401
}
402402
if ( \preg_match( '/signature="(.*?)"/ism', $signature, $matches ) ) {
403-
$parsed_header['signature'] = \base64_decode( preg_replace( '/\s+/', '', trim( $matches[1] ) ) ); // phpcs:ignore
403+
$parsed_header['signature'] = \base64_decode( preg_replace( '/\s+/', '', trim( $matches[1] ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
404404
}
405405

406406
if ( ( $parsed_header['signature'] ) && ( $parsed_header['algorithm'] ) && ( ! $parsed_header['headers'] ) ) {

includes/collection/class-followers.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static function remove_follower( $user_id, $actor ) {
9494
public static function get_follower( $user_id, $actor ) {
9595
global $wpdb;
9696

97-
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
97+
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
9898
$post_id = $wpdb->get_var(
9999
$wpdb->prepare(
100100
"SELECT DISTINCT p.ID FROM $wpdb->posts p INNER JOIN $wpdb->postmeta pm ON p.ID = pm.post_id WHERE p.post_type = %s AND pm.meta_key = 'activitypub_user_id' AND pm.meta_value = %d AND p.guid = %s",
@@ -119,12 +119,12 @@ public static function get_follower( $user_id, $actor ) {
119119
*
120120
* @param string $actor The Actor URL.
121121
*
122-
* @return Follower|null The Follower object or null.
122+
* @return \Activitypub\Activity\Base_Object|WP_Error|null
123123
*/
124124
public static function get_follower_by_actor( $actor ) {
125125
global $wpdb;
126126

127-
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
127+
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
128128
$post_id = $wpdb->get_var(
129129
$wpdb->prepare(
130130
"SELECT ID FROM $wpdb->posts WHERE guid=%s",

includes/functions.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,8 +1012,7 @@ function ( $enclosure ) {
10121012
function get_comment_ancestors( $comment ) {
10131013
$comment = \get_comment( $comment );
10141014

1015-
// phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual
1016-
if ( ! $comment || empty( $comment->comment_parent ) || $comment->comment_parent == $comment->comment_ID ) {
1015+
if ( ! $comment || empty( $comment->comment_parent ) || (int) $comment->comment_parent === (int) $comment->comment_ID ) {
10171016
return array();
10181017
}
10191018

includes/handler/class-announce.php

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,25 @@ public static function init() {
3333
/**
3434
* Handles "Announce" requests.
3535
*
36-
* @param array $array The activity-object.
37-
* @param int $user_id The id of the local blog-user.
38-
* @param \Activitypub\Activity\Activity $activity The activity object.
39-
*
40-
* @return void
36+
* @param array $announcement The activity-object.
37+
* @param int $user_id The id of the local blog-user.
38+
* @param \Activitypub\Activity\Activity $activity The activity object.
4139
*/
42-
public static function handle_announce( $array, $user_id, $activity = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound
40+
public static function handle_announce( $announcement, $user_id, $activity = null ) {
4341
// Check if Activity is public or not.
44-
if ( ! is_activity_public( $array ) ) {
42+
if ( ! is_activity_public( $announcement ) ) {
4543
// @todo maybe send email
4644
return;
4745
}
4846

4947
if ( ! ACTIVITYPUB_DISABLE_REACTIONS ) {
50-
self::maybe_save_announce( $array, $user_id, $activity );
48+
self::maybe_save_announce( $announcement, $user_id );
5149
}
5250

53-
if ( is_string( $array['object'] ) ) {
54-
$object = Http::get_remote_object( $array['object'] );
51+
if ( is_string( $announcement['object'] ) ) {
52+
$object = Http::get_remote_object( $announcement['object'] );
5553
} else {
56-
$object = $array['object'];
54+
$object = $announcement['object'];
5755
}
5856

5957
if ( ! $object || is_wp_error( $object ) ) {
@@ -66,21 +64,33 @@ public static function handle_announce( $array, $user_id, $activity = null ) { /
6664

6765
$type = \strtolower( $object['type'] );
6866

67+
/**
68+
* Fires after an Announce has been received.
69+
*
70+
* @param array $object The object.
71+
* @param int $user_id The id of the local blog-user.
72+
* @param array $activity The activity object.
73+
*/
6974
\do_action( 'activitypub_inbox', $object, $user_id, $type, $activity );
75+
76+
/**
77+
* Fires after an Announce of a specific type has been received.
78+
*
79+
* @param array $object The object.
80+
* @param int $user_id The id of the local blog-user.
81+
* @param array $activity The activity object.
82+
*/
7083
\do_action( "activitypub_inbox_{$type}", $object, $user_id, $activity );
7184
}
7285

7386
/**
7487
* Try to save the Announce.
7588
*
76-
* @param array $array The activity-object.
77-
* @param int $user_id The id of the local blog-user.
78-
* @param \Activitypub\Activity\Activity $activity The activity object.
79-
*
80-
* @return void
89+
* @param array $activity The activity-object.
90+
* @param int $user_id The id of the local blog-user.
8191
*/
82-
public static function maybe_save_announce( $array, $user_id, $activity ) { // phpcs:ignore
83-
$url = object_to_uri( $array['object'] );
92+
public static function maybe_save_announce( $activity, $user_id ) {
93+
$url = object_to_uri( $activity['object'] );
8494

8595
if ( empty( $url ) ) {
8696
return;
@@ -91,13 +101,21 @@ public static function maybe_save_announce( $array, $user_id, $activity ) { // p
91101
return;
92102
}
93103

94-
$state = Interactions::add_reaction( $array );
104+
$state = Interactions::add_reaction( $activity );
95105
$reaction = null;
96106

97107
if ( $state && ! is_wp_error( $state ) ) {
98108
$reaction = get_comment( $state );
99109
}
100110

101-
do_action( 'activitypub_handled_announce', $array, $user_id, $state, $reaction );
111+
/**
112+
* Fires after an Announce has been saved.
113+
*
114+
* @param array $activity The activity-object.
115+
* @param int $user_id The id of the local blog-user.
116+
* @param mixed $state The state of the reaction.
117+
* @param mixed $reaction The reaction.
118+
*/
119+
do_action( 'activitypub_handled_announce', $activity, $user_id, $state, $reaction );
102120
}
103121
}

includes/handler/class-like.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,15 @@ public static function init() {
3131
/**
3232
* Handles "Like" requests.
3333
*
34-
* @param array $array The Activity array.
35-
* @param int $user_id The ID of the local blog user.
36-
* @param \Activitypub\Activity\Activity $activity The Activity object.
37-
*
38-
* @return void
34+
* @param array $like The Activity array.
35+
* @param int $user_id The ID of the local blog user.
3936
*/
40-
public static function handle_like( $array, $user_id, $activity = null ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound,VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable,Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
37+
public static function handle_like( $like, $user_id ) {
4138
if ( ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) {
4239
return;
4340
}
4441

45-
$url = object_to_uri( $array['object'] );
42+
$url = object_to_uri( $like['object'] );
4643

4744
if ( empty( $url ) ) {
4845
return;
@@ -53,13 +50,21 @@ public static function handle_like( $array, $user_id, $activity = null ) { // ph
5350
return;
5451
}
5552

56-
$state = Interactions::add_reaction( $array );
53+
$state = Interactions::add_reaction( $like );
5754
$reaction = null;
5855

5956
if ( $state && ! is_wp_error( $state ) ) {
6057
$reaction = get_comment( $state );
6158
}
6259

63-
do_action( 'activitypub_handled_like', $array, $user_id, $state, $reaction );
60+
/**
61+
* Fires after a Like has been handled.
62+
*
63+
* @param array $like The Activity array.
64+
* @param int $user_id The ID of the local blog user.
65+
* @param mixed $state The state of the reaction.
66+
* @param mixed $reaction The reaction object.
67+
*/
68+
do_action( 'activitypub_handled_like', $like, $user_id, $state, $reaction );
6469
}
6570
}

includes/model/class-follower.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function save() {
149149
if ( ! $this->get__id() ) {
150150
global $wpdb;
151151

152-
// phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching
152+
// phpcs:ignore WordPress.DB.DirectDatabaseQuery
153153
$post_id = $wpdb->get_var(
154154
$wpdb->prepare(
155155
"SELECT ID FROM $wpdb->posts WHERE guid=%s",

includes/rest/class-outbox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public static function user_outbox_get( $request ) {
102102
$json->next = \add_query_arg( 'page', $page + 1, $json->partOf );
103103
}
104104

105-
if ( $page && ( $page > 1 ) ) { // phpcs:ignore
105+
if ( $page && ( $page > 1 ) ) {
106106
$json->prev = \add_query_arg( 'page', $page - 1, $json->partOf );
107107
}
108108
// phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase

includes/table/class-followers.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,26 +92,22 @@ public function prepare_items() {
9292

9393
$args = array();
9494

95-
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
95+
// phpcs:disable WordPress.Security.NonceVerification.Recommended
9696
if ( isset( $_GET['orderby'] ) ) {
97-
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
9897
$args['orderby'] = sanitize_text_field( wp_unslash( $_GET['orderby'] ) );
9998
}
10099

101-
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
102100
if ( isset( $_GET['order'] ) ) {
103-
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
104101
$args['order'] = sanitize_text_field( wp_unslash( $_GET['order'] ) );
105102
}
106103

107-
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
108104
if ( isset( $_GET['s'] ) && isset( $_REQUEST['_wpnonce'] ) ) {
109105
$nonce = sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) );
110106
if ( wp_verify_nonce( $nonce, 'bulk-' . $this->_args['plural'] ) ) {
111-
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
112107
$args['s'] = sanitize_text_field( wp_unslash( $_GET['s'] ) );
113108
}
114109
}
110+
// phpcs:enable WordPress.Security.NonceVerification.Recommended
115111

116112
$followers_with_count = FollowerCollection::get_followers_with_count( $this->user_id, $per_page, $page_num, $args );
117113
$followers = $followers_with_count['followers'];
@@ -219,7 +215,7 @@ public function process_action() {
219215
return;
220216
}
221217

222-
$followers = $_REQUEST['followers']; // phpcs:ignore
218+
$followers = $_REQUEST['followers']; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput
223219

224220
if ( $this->current_action() === 'delete' ) {
225221
if ( ! is_array( $followers ) ) {

includes/transformer/class-factory.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,22 @@
1010
use WP_Error;
1111

1212
/**
13-
* Transformer Factory
13+
* Transformer Factory.
1414
*/
1515
class Factory {
1616
/**
1717
* Get the transformer for a given object.
1818
*
19-
* @param mixed $object The object to transform.
19+
* @param mixed $data The object to transform.
20+
*
2021
* @return Base|WP_Error The transformer to use, or an error.
2122
*/
22-
public static function get_transformer( $object ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.objectFound
23-
if ( ! \is_object( $object ) ) {
23+
public static function get_transformer( $data ) {
24+
if ( ! \is_object( $data ) ) {
2425
return new WP_Error( 'invalid_object', __( 'Invalid object', 'activitypub' ) );
2526
}
2627

27-
$class = \get_class( $object );
28+
$class = \get_class( $data );
2829

2930
/**
3031
* Filter the transformer for a given object.
@@ -50,12 +51,12 @@ public static function get_transformer( $object ) { // phpcs:ignore Universal.Na
5051
* }, 10, 3 );
5152
*
5253
* @param Base $transformer The transformer to use.
53-
* @param mixed $object The object to transform.
54+
* @param mixed $data The object to transform.
5455
* @param string $object_class The class of the object to transform.
5556
*
5657
* @return mixed The transformer to use.
5758
*/
58-
$transformer = \apply_filters( 'activitypub_transformer', null, $object, $class );
59+
$transformer = \apply_filters( 'activitypub_transformer', null, $data, $class );
5960

6061
if ( $transformer ) {
6162
if (
@@ -71,12 +72,12 @@ public static function get_transformer( $object ) { // phpcs:ignore Universal.Na
7172
// Use default transformer.
7273
switch ( $class ) {
7374
case 'WP_Post':
74-
if ( 'attachment' === $object->post_type ) {
75-
return new Attachment( $object );
75+
if ( 'attachment' === $data->post_type ) {
76+
return new Attachment( $data );
7677
}
77-
return new Post( $object );
78+
return new Post( $data );
7879
case 'WP_Comment':
79-
return new Comment( $object );
80+
return new Comment( $data );
8081
default:
8182
return null;
8283
}

0 commit comments

Comments
 (0)