Skip to content

Commit 00a57c3

Browse files
obenlandpfefferle
andauthored
PHPCS: Enable Commenting sniff (#925)
* PHPCS: Enable Commenting sniff * Apply suggestions from code review Co-authored-by: Matthias Pfefferle <pfefferle@users.noreply.github.com> * Fix param alignment. --------- Co-authored-by: Matthias Pfefferle <pfefferle@users.noreply.github.com>
1 parent 0625090 commit 00a57c3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2362
-1430
lines changed

activitypub.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
* Requires PHP: 7.0
1212
* Text Domain: activitypub
1313
* Domain Path: /languages
14+
*
15+
* @package Activitypub
1416
*/
1517

1618
namespace Activitypub;
1719

1820
use WP_CLI;
1921

20-
use function Activitypub\is_blog_public;
21-
use function Activitypub\site_supports_blocks;
22-
2322
require_once __DIR__ . '/includes/compat.php';
2423
require_once __DIR__ . '/includes/functions.php';
2524

@@ -39,7 +38,7 @@
3938
\defined( 'ACTIVITYPUB_AUTHORIZED_FETCH' ) || \define( 'ACTIVITYPUB_AUTHORIZED_FETCH', false );
4039
\defined( 'ACTIVITYPUB_DISABLE_REWRITES' ) || \define( 'ACTIVITYPUB_DISABLE_REWRITES', false );
4140
\defined( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS', false );
42-
// Disable reactions like `Like` and `Announce` by default
41+
// Disable reactions like `Like` and `Announce` by default.
4342
\defined( 'ACTIVITYPUB_DISABLE_REACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_REACTIONS', true );
4443
\defined( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS', false );
4544
\defined( 'ACTIVITYPUB_SHARED_INBOX_FEATURE' ) || \define( 'ACTIVITYPUB_SHARED_INBOX_FEATURE', false );
@@ -66,7 +65,7 @@ function rest_init() {
6665
Rest\Collection::init();
6766
Rest\Interaction::init();
6867

69-
// load NodeInfo endpoints only if blog is public
68+
// Load NodeInfo endpoints only if blog is public.
7069
if ( is_blog_public() ) {
7170
Rest\NodeInfo::init();
7271
}
@@ -103,7 +102,7 @@ function plugin_init() {
103102

104103

105104
/**
106-
* Class Autoloader
105+
* Class Autoloader.
107106
*/
108107
\spl_autoload_register(
109108
function ( $full_class ) {
@@ -131,7 +130,7 @@ function ( $full_class ) {
131130
if ( file_exists( $file ) && is_readable( $file ) ) {
132131
require_once $file;
133132
} else {
134-
// translators: %s is the class name
133+
// translators: %s is the class name.
135134
$message = sprintf( esc_html__( 'Required class not found or not readable: %s', 'activitypub' ), esc_html( $full_class ) );
136135
Debug::write_log( $message );
137136
\wp_die( $message ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
@@ -141,7 +140,9 @@ function ( $full_class ) {
141140
);
142141

143142
/**
144-
* Add plugin settings link
143+
* Add plugin settings link.
144+
*
145+
* @param array $actions The current actions.
145146
*/
146147
function plugin_settings_link( $actions ) {
147148
$settings_link = array();
@@ -179,13 +180,14 @@ function plugin_settings_link( $actions ) {
179180
)
180181
);
181182

182-
// Load integrations
183+
// Load integrations.
183184
require_once __DIR__ . '/integration/load.php';
184185

185186
/**
186-
* `get_plugin_data` wrapper
187+
* `get_plugin_data` wrapper.
187188
*
188-
* @return array The plugin metadata array
189+
* @param array $default_headers Optional. The default plugin headers. Default empty array.
190+
* @return array The plugin metadata array.
189191
*/
190192
function get_plugin_meta( $default_headers = array() ) {
191193
if ( ! $default_headers ) {
@@ -221,7 +223,7 @@ function get_plugin_version() {
221223
return $meta['Version'];
222224
}
223225

224-
// Check for CLI env, to add the CLI commands
226+
// Check for CLI env, to add the CLI commands.
225227
if ( defined( 'WP_CLI' ) && WP_CLI ) {
226228
WP_CLI::add_command(
227229
'activitypub',

includes/activity/class-activity.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
* Inspired by the PHP ActivityPub Library by @Landrok
44
*
55
* @link https://github.com/landrok/activitypub
6+
*
7+
* @package Activitypub
68
*/
79

810
namespace Activitypub\Activity;
911

10-
use Activitypub\Activity\Base_Object;
12+
use Activitypub\Link;
1113

1214
/**
1315
* \Activitypub\Activity\Activity implements the common
@@ -150,12 +152,12 @@ class Activity extends Base_Object {
150152
* @return void
151153
*/
152154
public function set_object( $data ) {
153-
// convert array to object
155+
// Convert array to object.
154156
if ( is_array( $data ) ) {
155157
$data = self::init_from_array( $data );
156158
}
157159

158-
// set object
160+
// Set object.
159161
$this->set( 'object', $data );
160162

161163
if ( ! is_object( $data ) ) {
@@ -202,7 +204,7 @@ public function get_json_ld_context() {
202204
if ( $this->object instanceof Base_Object ) {
203205
$class = get_class( $this->object );
204206
if ( $class && $class::JSON_LD_CONTEXT ) {
205-
// Without php 5.6 support this could be just: 'return $this->object::JSON_LD_CONTEXT;'
207+
// Without php 5.6 support this could be just: 'return $this->object::JSON_LD_CONTEXT;'.
206208
return $class::JSON_LD_CONTEXT;
207209
}
208210
}

includes/activity/class-actor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Inspired by the PHP ActivityPub Library by @Landrok
44
*
55
* @link https://github.com/landrok/activitypub
6+
*
7+
* @package Activitypub
68
*/
79

810
namespace Activitypub\Activity;

includes/activity/class-base-object.php

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Inspired by the PHP ActivityPub Library by @Landrok
44
*
55
* @link https://github.com/landrok/activitypub
6+
*
7+
* @package Activitypub
68
*/
79

810
namespace Activitypub\Activity;
@@ -431,7 +433,7 @@ class Base_Object {
431433
*
432434
* @see https://www.w3.org/TR/activitypub/#source-property
433435
*
434-
* @var ObjectType
436+
* @var array
435437
*/
436438
protected $source;
437439

@@ -460,12 +462,10 @@ class Base_Object {
460462
protected $sensitive = false;
461463

462464
/**
463-
* Magic function to implement getter and setter
465+
* Magic function to implement getter and setter.
464466
*
465467
* @param string $method The method name.
466468
* @param string $params The method params.
467-
*
468-
* @return void
469469
*/
470470
public function __call( $method, $params ) {
471471
$var = \strtolower( \substr( $method, 4 ) );
@@ -577,9 +577,9 @@ public function add( $key, $value ) {
577577
/**
578578
* Convert JSON input to an array.
579579
*
580-
* @return string The JSON string.
580+
* @param string $json The JSON string.
581581
*
582-
* @return \Activitypub\Activity\Base_Object An Object built from the JSON string.
582+
* @return Base_Object An Object built from the JSON string.
583583
*/
584584
public static function init_from_json( $json ) {
585585
$array = \json_decode( $json, true );
@@ -653,12 +653,12 @@ public function to_array( $include_json_ld_context = true ) {
653653
$vars = get_object_vars( $this );
654654

655655
foreach ( $vars as $key => $value ) {
656-
// ignotre all _prefixed keys.
656+
// Ignore all _prefixed keys.
657657
if ( '_' === substr( $key, 0, 1 ) ) {
658658
continue;
659659
}
660660

661-
// if value is empty, try to get it from a getter.
661+
// If value is empty, try to get it from a getter.
662662
if ( ! $value ) {
663663
$value = call_user_func( array( $this, 'get_' . $key ) );
664664
}
@@ -667,7 +667,7 @@ public function to_array( $include_json_ld_context = true ) {
667667
$value = $value->to_array( false );
668668
}
669669

670-
// if value is still empty, ignore it for the array and continue.
670+
// If value is still empty, ignore it for the array and continue.
671671
if ( isset( $value ) ) {
672672
$array[ snake_to_camel_case( $key ) ] = $value;
673673
}
@@ -681,10 +681,28 @@ public function to_array( $include_json_ld_context = true ) {
681681
$class = new ReflectionClass( $this );
682682
$class = strtolower( $class->getShortName() );
683683

684+
/**
685+
* Filter the array of the ActivityPub object.
686+
*
687+
* @param array $array The array of the ActivityPub object.
688+
* @param string $class The class of the ActivityPub object.
689+
* @param int $id The ID of the ActivityPub object.
690+
* @param Base_Object $object The ActivityPub object.
691+
*
692+
* @return array The filtered array of the ActivityPub object.
693+
*/
684694
$array = \apply_filters( 'activitypub_activity_object_array', $array, $class, $this->id, $this );
685-
$array = \apply_filters( "activitypub_activity_{$class}_object_array", $array, $this->id, $this );
686695

687-
return $array;
696+
/**
697+
* Filter the array of the ActivityPub object by class.
698+
*
699+
* @param array $array The array of the ActivityPub object.
700+
* @param int $id The ID of the ActivityPub object.
701+
* @param Base_Object $object The ActivityPub object.
702+
*
703+
* @return array The filtered array of the ActivityPub object.
704+
*/
705+
return \apply_filters( "activitypub_activity_{$class}_object_array", $array, $this->id, $this );
688706
}
689707

690708
/**
@@ -698,11 +716,11 @@ public function to_json( $include_json_ld_context = true ) {
698716
$array = $this->to_array( $include_json_ld_context );
699717
$options = \JSON_HEX_TAG | \JSON_HEX_AMP | \JSON_HEX_QUOT;
700718

701-
/*
702-
* Options to be passed to json_encode()
703-
*
704-
* @param int $options The current options flags
705-
*/
719+
/**
720+
* Options to be passed to json_encode()
721+
*
722+
* @param int $options The current options flags.
723+
*/
706724
$options = \apply_filters( 'activitypub_json_encode_options', $options );
707725

708726
return \wp_json_encode( $array, $options );

includes/activity/extended-object/class-event.php

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
class Event extends Base_Object {
2020
// Human friendly minimal context for full Mobilizon compatible ActivityPub events.
2121
const JSON_LD_CONTEXT = array(
22-
'https://schema.org/', // The base context is schema.org, cause it is used a lot.
23-
'https://www.w3.org/ns/activitystreams', // The ActivityStreams context overrides everyting also defined in schema.org.
22+
'https://schema.org/', // The base context is schema.org, because it is used a lot.
23+
'https://www.w3.org/ns/activitystreams', // The ActivityStreams context overrides everything also defined in schema.org.
2424
array( // The keys here override/extend the context even more.
2525
'pt' => 'https://joinpeertube.org/ns#',
2626
'mz' => 'https://joinmobilizon.org/ns#',
@@ -59,7 +59,7 @@ class Event extends Base_Object {
5959
/**
6060
* Mobilizon compatible values for joinModeTypes.
6161
*/
62-
const JOIN_MODE_TYPES = array( 'free', 'restricted', 'external' ); // and 'invite', but not used by mobilizon atm
62+
const JOIN_MODE_TYPES = array( 'free', 'restricted', 'external' ); // and 'invite', but not used by mobilizon atm.
6363

6464
/**
6565
* Allowed values for ical VEVENT STATUS.
@@ -109,8 +109,7 @@ class Event extends Base_Object {
109109
);
110110

111111
/**
112-
* Event is an implementation of one of the
113-
* Activity Streams
112+
* Event is an implementation of one of the Activity Streams.
114113
*
115114
* @var string
116115
*/
@@ -124,7 +123,7 @@ class Event extends Base_Object {
124123
protected $name;
125124

126125
/**
127-
* The events contacts
126+
* The events contacts.
128127
*
129128
* @context {
130129
* '@id' => 'mz:contacts',
@@ -200,7 +199,7 @@ class Event extends Base_Object {
200199
* The event's status.
201200
*
202201
* @context https://www.w3.org/2002/12/cal/ical#status
203-
* @var enum
202+
* @var string
204203
*/
205204
protected $status;
206205

@@ -263,6 +262,7 @@ class Event extends Base_Object {
263262
* The passed timezone is only set when it is a valid one, otherwise the site's timezone is used.
264263
*
265264
* @param string $timezone The timezone string to be set, e.g. 'Europe/Berlin'.
265+
* @return Event
266266
*/
267267
public function set_timezone( $timezone ) {
268268
if ( in_array( $timezone, timezone_identifiers_list(), true ) ) {
@@ -275,9 +275,11 @@ public function set_timezone( $timezone ) {
275275
}
276276

277277
/**
278-
* Custom setter for repliesModerationOption which also directy sets commentsEnabled accordingly.
278+
* Custom setter for repliesModerationOption which also directly sets commentsEnabled accordingly.
279+
*
280+
* @param string $type The type of the replies moderation option.
279281
*
280-
* @param string $type
282+
* @return Event
281283
*/
282284
public function set_replies_moderation_option( $type ) {
283285
if ( in_array( $type, self::REPLIES_MODERATION_OPTION_TYPES, true ) ) {
@@ -297,7 +299,9 @@ public function set_replies_moderation_option( $type ) {
297299
/**
298300
* Custom setter for commentsEnabled which also directly sets repliesModerationOption accordingly.
299301
*
300-
* @param bool $comments_enabled
302+
* @param bool $comments_enabled Whether comments are enabled.
303+
*
304+
* @return Event
301305
*/
302306
public function set_comments_enabled( $comments_enabled ) {
303307
if ( is_bool( $comments_enabled ) ) {
@@ -317,7 +321,9 @@ public function set_comments_enabled( $comments_enabled ) {
317321
/**
318322
* Custom setter for the ical status that checks whether the status is an ical event status.
319323
*
320-
* @param string $status
324+
* @param string $status The status of the event.
325+
*
326+
* @return Event
321327
*/
322328
public function set_status( $status ) {
323329
if ( in_array( $status, self::ICAL_EVENT_STATUS_TYPES, true ) ) {
@@ -338,8 +344,10 @@ public function set_status( $status ) {
338344
*
339345
* Falls back to Mobilizons default category.
340346
*
341-
* @param string $category
342-
* @param bool $mobilizon_compatibilty Whether the category must be compatibly with Mobilizon.
347+
* @param string $category The category of the event.
348+
* @param bool $mobilizon_compatibilty Optional. Whether the category must be compatibly with Mobilizon. Default true.
349+
*
350+
* @return Event
343351
*/
344352
public function set_category( $category, $mobilizon_compatibilty = true ) {
345353
if ( $mobilizon_compatibilty ) {
@@ -356,7 +364,9 @@ public function set_category( $category, $mobilizon_compatibilty = true ) {
356364
*
357365
* Automatically sets the joinMode to true if called.
358366
*
359-
* @param string $url
367+
* @param string $url The URL for external participation.
368+
*
369+
* @return Event
360370
*/
361371
public function set_external_participation_url( $url ) {
362372
if ( preg_match( '/^https?:\/\/.*/i', $url ) ) {

includes/activity/extended-object/class-place.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ class Place extends Base_Object {
8686
*/
8787
protected $address;
8888

89+
/**
90+
* Set the address of the place.
91+
*
92+
* @param array|string $address The address of the place.
93+
*/
8994
public function set_address( $address ) {
9095
if ( is_string( $address ) || is_array( $address ) ) {
9196
$this->address = $address;

0 commit comments

Comments
 (0)