Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 2815951

Browse files
committed
Additional PHPCS inspired fixes
1 parent ac2acce commit 2815951

File tree

5 files changed

+72
-58
lines changed

5 files changed

+72
-58
lines changed

includes/class-linkbacks-handler.php

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static function register_meta() {
108108
*/
109109
public static function enhance( $commentdata, $comment = array(), $commentarr = array() ) {
110110
// check if comment is a linkback
111-
if ( ! in_array( $commentdata['comment_type'], array( 'webmention', 'pingback', 'trackback' ) ) ) {
111+
if ( ! in_array( $commentdata['comment_type'], array( 'webmention', 'pingback', 'trackback' ), true ) ) {
112112
return $commentdata;
113113
}
114114

@@ -139,7 +139,7 @@ public static function enhance( $commentdata, $comment = array(), $commentarr =
139139

140140
// remove "webmention" comment-type if $type is "reply"
141141
if ( isset( $commentdata['comment_meta']['semantic_linkbacks_type'] ) ) {
142-
if ( in_array( $commentdata['comment_meta']['semantic_linkbacks_type'], apply_filters( 'semantic_linkbacks_comment_types', array( 'reply' ) ) ) ) {
142+
if ( in_array( $commentdata['comment_meta']['semantic_linkbacks_type'], apply_filters( 'semantic_linkbacks_comment_types', array( 'reply' ) ), true ) ) {
143143
$commentdata['comment_type'] = '';
144144
}
145145
}
@@ -188,19 +188,29 @@ public static function update_meta( $comment_id, $commentdata ) {
188188
*/
189189
public static function get_comment_type_excerpts() {
190190
$strings = array(
191-
// special case. any value that evals to false will be considered standard
191+
// translators: Name verb on domain
192192
'mention' => __( '%1$s mentioned %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
193-
193+
// translators: Name verb on domain
194194
'reply' => __( '%1$s replied to %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
195+
// translators: Name verb on domain
195196
'repost' => __( '%1$s reposted %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
197+
// translators: Name verb on domain
196198
'like' => __( '%1$s liked %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
199+
// translators: Name verb on domain
197200
'favorite' => __( '%1$s favorited %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
201+
// translators: Name verb on domain
198202
'tag' => __( '%1$s tagged %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
203+
// translators: Name verb on domain
199204
'bookmark' => __( '%1$s bookmarked %2$s on <a href="%3$s">%4$s</a>.', 'semantic-linkbacks' ),
205+
// translators: Name verb on domain
200206
'rsvp:yes' => __( '%1$s is <strong>attending</strong>.', 'semantic-linkbacks' ),
207+
// translators: Name verb on domain
201208
'rsvp:no' => __( '%1$s is <strong>not attending</strong>.', 'semantic-linkbacks' ),
209+
// translators: Name verb on domain
202210
'rsvp:maybe' => __( 'Maybe %1$s will be <strong>attending</strong>.', 'semantic-linkbacks' ),
211+
// translators: Name verb on domain
203212
'rsvp:invited' => __( '%1$s is <strong>invited</strong>.', 'semantic-linkbacks' ),
213+
// translators: Name verb on domain
204214
'rsvp:tracking' => __( '%1$s <strong>tracks</strong> this event.', 'semantic-linkbacks' ),
205215
);
206216

@@ -348,13 +358,13 @@ public static function comment_text_add_cite( $text, $comment = null, $args = ar
348358

349359
// only change text for "real" comments (replys)
350360
if ( ! $semantic_linkbacks_type ||
351-
'' != $comment->comment_type ||
352-
'reply' != $semantic_linkbacks_type ) {
361+
'' !== $comment->comment_type ||
362+
'reply' !== $semantic_linkbacks_type ) {
353363
return $text;
354364
}
355365

356366
$url = self::get_url( $comment );
357-
$host = parse_url( $url, PHP_URL_HOST );
367+
$host = wp_parse_url( $url, PHP_URL_HOST );
358368

359369
// strip leading www, if any
360370
$host = preg_replace( '/^www\./', '', $host );
@@ -387,14 +397,14 @@ public static function comment_text_excerpt( $text, $comment = null, $args = arr
387397
$semantic_linkbacks_type = self::get_type( $comment );
388398

389399
// only change text for pingbacks/trackbacks/webmentions
390-
if ( '' == $comment->comment_type ||
400+
if ( '' === $comment->comment_type ||
391401
! $semantic_linkbacks_type ||
392-
'reply' == $semantic_linkbacks_type ) {
402+
'reply' === $semantic_linkbacks_type ) {
393403
return $text;
394404
}
395405

396406
// check semantic linkback type
397-
if ( ! in_array( $semantic_linkbacks_type, array_keys( self::get_comment_type_strings() ) ) ) {
407+
if ( ! in_array( $semantic_linkbacks_type, array_keys( self::get_comment_type_strings() ), true ) ) {
398408
$semantic_linkbacks_type = 'mention';
399409
}
400410

@@ -403,7 +413,7 @@ public static function comment_text_excerpt( $text, $comment = null, $args = arr
403413
} else {
404414
$post_format = get_post_format( $comment->comment_post_ID );
405415
// add "standard" as default
406-
if ( ! $post_format || ! in_array( $post_format, array_keys( self::get_post_format_strings() ) ) ) {
416+
if ( ! $post_format || ! in_array( $post_format, array_keys( self::get_post_format_strings() ), true ) ) {
407417
$post_format = 'standard';
408418
}
409419
}
@@ -426,7 +436,7 @@ public static function comment_text_excerpt( $text, $comment = null, $args = arr
426436

427437
// generate output. use full content if it's small enough, otherwise use excerpt.
428438
$text_len = mb_strlen( html_entity_decode( $text, ENT_QUOTES ) );
429-
if ( ! ( 'mention' == $semantic_linkbacks_type && $text_len <= MAX_INLINE_MENTION_LENGTH ) ) {
439+
if ( ! ( 'mention' === $semantic_linkbacks_type && $text_len <= MAX_INLINE_MENTION_LENGTH ) ) {
430440
$text = sprintf( $comment_type_excerpts[ $semantic_linkbacks_type ], get_comment_author_link( $comment->comment_ID ), $post_type, $url, $host );
431441
}
432442
return apply_filters( 'semantic_linkbacks_excerpt', $text );

includes/class-linkbacks-mf2-handler.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ public static function generate_commentdata( $commentdata ) {
127127
}
128128

129129
$commentdata['remote_source_mf2'] = $entry;
130-
$commentdata['remote_source_properties'] = $properties = array_filter( self::flatten_microformats( $entry ) );
131-
$commentdata['remote_source_rels'] = $rels = $mf_array['rels'];
130+
$properties = array_filter( self::flatten_microformats( $entry ) );
131+
$commentdata['remote_source_properties'] = $properties;
132+
$rels = $mf_array['rels'];
133+
$commentdata['remote_source_rels'] = $rels;
132134

133135
// try to find some content
134136
// @link http://indiewebcamp.com/comments-presentation
@@ -167,7 +169,8 @@ public static function generate_commentdata( $commentdata ) {
167169
if ( ! is_wp_error( $response ) ) {
168170
$parser = new Parser( wp_remote_retrieve_body( $response ), $author );
169171
$author_array = $parser->parse( true );
170-
$properties['author'] = $author = self::flatten_microformats( self::get_representative_author( $author_array, $author ) );
172+
$author = self::flatten_microformats( self::get_representative_author( $author_array, $author ) );
173+
$properties['author'] = $author;
171174
}
172175
} else {
173176
$commentdata['comment_author'] = wp_slash( $author );
@@ -177,7 +180,8 @@ public static function generate_commentdata( $commentdata ) {
177180
if ( is_array( $author ) ) {
178181
if ( ! isset( $author['me'] ) ) {
179182
if ( isset( $mf_array['rels']['me'] ) ) {
180-
$properties['author']['me'] = $author['me'] = $mf_array['rels']['me'];
183+
$author['me'] = $mf_array['rels']['me'];
184+
$properties['author']['me'] = $author['me'];
181185
}
182186
}
183187
if ( isset( $author['name'] ) ) {
@@ -224,7 +228,7 @@ public static function generate_commentdata( $commentdata ) {
224228
$commentdata['comment_meta']['geo_address'] = self::first( $location['name'] );
225229
}
226230
} else {
227-
if ( substr( $location, 0, 4 ) == 'geo:' ) {
231+
if ( substr( $location, 0, 4 ) === 'geo:' ) {
228232
$geo = explode( ':', substr( urldecode( $location ), 4 ) );
229233
$geo = explode( ';', $geo[0] );
230234
$coords = explode( ',', $geo[0] );
@@ -259,7 +263,7 @@ public static function generate_commentdata( $commentdata ) {
259263
$whitelist = array_merge( $whitelist, array_keys( self::get_class_mapper() ) );
260264
$whitelist = apply_filters( 'semantic_linkbacks_mf2_props_whitelist', $whitelist );
261265
foreach ( $properties as $key => $value ) {
262-
if ( in_array( $key, $whitelist ) ) {
266+
if ( in_array( $key, $whitelist, true ) ) {
263267
if ( self::is_url( $value ) ) {
264268
$value = esc_url_raw( $value );
265269
}
@@ -288,7 +292,7 @@ public static function get_property( $key, $properties ) {
288292
if ( is_array( $properties[ $key ] ) ) {
289293
$properties[ $key ] = array_unique( $properties[ $key ] );
290294
}
291-
if ( 1 == count( $properties[ $key ] ) ) {
295+
if ( 1 === count( $properties[ $key ] ) ) {
292296
return $properties[ $key ][0];
293297
}
294298
return $properties[ $key ];
@@ -326,7 +330,7 @@ public static function is_url( $string ) {
326330

327331
// Accepted h types
328332
public static function is_h( $string ) {
329-
return in_array( $string, array( 'h-cite', 'h-entry', 'h-feed', 'h-product', 'h-event', 'h-review', 'h-recipe' ) );
333+
return in_array( $string, array( 'h-cite', 'h-entry', 'h-feed', 'h-product', 'h-event', 'h-review', 'h-recipe' ), true );
330334
}
331335

332336
public static function flatten_microformats( $item ) {
@@ -393,7 +397,7 @@ public static function get_entries( $mf_array ) {
393397
if ( ! isset( $mf_array['items'] ) ) {
394398
return $entries;
395399
}
396-
if ( 0 == count( $mf_array['items'] ) ) {
400+
if ( 0 === count( $mf_array['items'] ) ) {
397401
return $entries;
398402
}
399403

@@ -402,14 +406,14 @@ public static function get_entries( $mf_array ) {
402406

403407
// check if it is an h-feed
404408
if ( isset( $first_item['type'] ) &&
405-
in_array( 'h-feed', $first_item['type'] ) &&
409+
in_array( 'h-feed', $first_item['type'], true ) &&
406410
isset( $first_item['children'] ) ) {
407411
$mf_array['items'] = $first_item['children'];
408412
}
409413

410414
// iterate array
411415
foreach ( $mf_array['items'] as $mf ) {
412-
if ( isset( $mf['type'] ) && in_array( 'h-entry', $mf['type'] ) ) {
416+
if ( isset( $mf['type'] ) && in_array( 'h-entry', $mf['type'], true ) ) {
413417
$entries[] = $mf;
414418
}
415419
}
@@ -429,16 +433,15 @@ public static function get_entries( $mf_array ) {
429433
public static function get_representative_author( $mf_array, $source ) {
430434
foreach ( $mf_array['items'] as $mf ) {
431435
if ( isset( $mf['type'] ) ) {
432-
if ( in_array( 'h-card', $mf['type'] ) ) {
436+
if ( in_array( 'h-card', $mf['type'], true ) ) {
433437
// check domain
434438
if ( isset( $mf['properties'] ) && isset( $mf['properties']['url'] ) ) {
435439
foreach ( $mf['properties']['url'] as $url ) {
436-
if ( wp_parse_url( $url, PHP_URL_HOST ) == wp_parse_url( $source, PHP_URL_HOST ) ) {
440+
if ( wp_parse_url( $url, PHP_URL_HOST ) === wp_parse_url( $source, PHP_URL_HOST ) ) {
437441
if ( isset( $mf_array['rels']['me'] ) ) {
438442
$mf['properties']['me'] = $mf_array['rels']['me'];
439443
}
440444
return $mf;
441-
break;
442445
}
443446
}
444447
}
@@ -492,10 +495,10 @@ public static function get_representative_entry( $entries, $target ) {
492495
// check properties if target urls was mentioned
493496
foreach ( $entry['properties'] as $key => $values ) {
494497
// check content for the link
495-
if ( 'content' == $key &&
498+
if ( 'content' === $key &&
496499
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $values[0]['html'], $context ) ) {
497500
return $entry;
498-
} elseif ( 'summary' == $key &&
501+
} elseif ( 'summary' === $key &&
499502
preg_match_all( '/<a[^>]+?' . preg_quote( $target, '/' ) . '[^>]*>([^>]+?)<\/a>/i', $values[0], $context ) ) {
500503
return $entry;
501504
}
@@ -522,7 +525,7 @@ public static function get_entry_type( $target, $entry, $mf_array = array() ) {
522525
// check properties for target-url
523526
foreach ( $entry['properties'] as $key => $values ) {
524527
// check u-* params
525-
if ( in_array( $key, array_keys( $classes ) ) ) {
528+
if ( in_array( $key, array_keys( $classes ), true ) ) {
526529
// check "normal" links
527530
if ( self::compare_urls( $target, $values ) ) {
528531
return $classes[ $key ];
@@ -554,9 +557,9 @@ public static function get_entry_type( $target, $entry, $mf_array = array() ) {
554557
// check rels for target-url
555558
foreach ( $mf_array['rels'] as $key => $values ) {
556559
// check rel params
557-
if ( in_array( $key, array_keys( $rels ) ) ) {
560+
if ( in_array( $key, array_keys( $rels ), true ) ) {
558561
foreach ( $values as $value ) {
559-
if ( $value == $target ) {
562+
if ( $value === $target ) {
560563
return $rels[ $key ];
561564
}
562565
}

includes/class-linkbacks-walker-comment.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class Semantic_Linkbacks_Walker_Comment extends Walker_Comment {
99
public static $reactions = array();
1010

11-
static function should_facepile( $comment ) {
11+
protected static function should_facepile( $comment ) {
1212
if ( self::is_reaction( $comment ) && get_option( 'semantic_linkbacks_facepile_reaction', true ) ) {
1313
return true;
1414
}
@@ -27,15 +27,15 @@ static function should_facepile( $comment ) {
2727

2828
$option = 'semantic_linkbacks_facepile_' . $type;
2929

30-
return $type && 'reply' != $type && get_option( $option, true );
30+
return $type && 'reply' !== $type && get_option( $option, true );
3131
}
3232

33-
static function get_comment_author_link( $comment_ID = 0 ) {
34-
$comment = get_comment( $comment_ID );
33+
protected static function get_comment_author_link( $comment_id = 0 ) {
34+
$comment = get_comment( $comment_id );
3535
$url = get_comment_author_url( $comment );
3636
$author = get_comment_author( $comment );
3737

38-
if ( empty( $url ) || 'http://' == $url ) {
38+
if ( empty( $url ) || 'http://' === $url ) {
3939
$return = sprintf( '<span class="p-name">%s</span>', $author );
4040
} else {
4141
$return = sprintf( '<a href="%s" rel="external" class="u-url p-name">%s</a>', $url, $author );
@@ -54,12 +54,12 @@ static function get_comment_author_link( $comment_ID = 0 ) {
5454
return apply_filters( 'get_comment_author_link', $return, $author, $comment->comment_ID );
5555
}
5656

57-
static function is_reaction( $comment ) {
58-
return ( $comment->type == '' &&
57+
protected static function is_reaction( $comment ) {
58+
return ( '' === $comment->type &&
5959
Emoji\is_single_emoji( trim( wp_strip_all_tags( $comment->comment_content ) ) ) );
6060
}
6161

62-
function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) {
62+
public function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) {
6363
if ( self::is_reaction( $comment ) ) {
6464
self::$reactions[] = $comment;
6565
}
@@ -69,7 +69,7 @@ function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) {
6969
}
7070
}
7171

72-
function end_el( &$output, $comment, $depth = 0, $args = array() ) {
72+
public function end_el( &$output, $comment, $depth = 0, $args = array() ) {
7373
if ( ! self::should_facepile( $comment ) ) {
7474
return parent::end_el( $output, $comment, $depth, $args );
7575
}
@@ -89,13 +89,14 @@ protected function _html5_comment( $comment, $depth, $args ) {
8989
<footer class="comment-meta">
9090
<div class="comment-author vcard h-card u-author">
9191
<?php
92-
if ( 0 != $args['avatar_size'] ) {
92+
if ( 0 !== $args['avatar_size'] ) {
9393
echo get_avatar( $comment, $args['avatar_size'] );}
9494
?>
9595
<?php
96-
/* translators: %s: comment author link */
96+
/* translators: %s: comment author */
9797
printf(
98-
__( '%s <span class="says">says:</span>' ),
98+
/* translators: %s: comment author link */
99+
__( '%s <span class="says">says:</span>', 'semantic-linkbacks' ),
99100
sprintf( '<b>%s</b>', self::get_comment_author_link( $comment ) )
100101
);
101102
if ( $type ) {
@@ -109,15 +110,15 @@ protected function _html5_comment( $comment, $depth, $args ) {
109110
<time class="dt-published" datetime="<?php comment_time( DATE_W3C ); ?>">
110111
<?php
111112
/* translators: 1: comment date, 2: comment time */
112-
printf( __( '%1$s at %2$s' ), get_comment_date( '', $comment ), get_comment_time() );
113+
printf( __( '%1$s at %2$s', 'semantic-linkbacks' ), get_comment_date( '', $comment ), get_comment_time() );
113114
?>
114115
</time>
115116
</a>
116-
<?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
117+
<?php edit_comment_link( __( 'Edit', 'semantic-linkbacks' ), '<span class="edit-link">', '</span>' ); ?>
117118
</div><!-- .comment-metadata -->
118119

119-
<?php if ( '0' == $comment->comment_approved ) : ?>
120-
<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></p>
120+
<?php if ( '0' === $comment->comment_approved ) : ?>
121+
<p class="comment-awaiting-moderation"><?php _e( 'Your response is awaiting moderation.', 'semantic-linkbacks' ); ?></p>
121122
<?php endif; ?>
122123
</footer><!-- .comment-meta -->
123124

includes/functions.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ function get_linkbacks_number( $type = null, $post_id = null ) {
1818
);
1919

2020
if ( $type ) { // use type if set
21-
if ( 'mention' == $type ) {
22-
$args['type__not_in'] = 'comment';
23-
$args['meta_query'] = array(
21+
if ( 'mention' === $type ) {
22+
$args['type__not_in'] = 'comment';
23+
$args['meta_query'] = array(
2424
'relation' => 'OR',
2525
array(
2626
'key' => 'semantic_linkbacks_type',
@@ -35,7 +35,7 @@ function get_linkbacks_number( $type = null, $post_id = null ) {
3535
'value' => 'mention',
3636
),
3737
);
38-
} elseif ( 'rsvp' == $type ) {
38+
} elseif ( 'rsvp' === $type ) {
3939
$args['meta_query'] = array(
4040
array(
4141
'key' => 'semantic_linkbacks_type',
@@ -88,9 +88,9 @@ function get_linkbacks( $type = null, $post_id = null, $order = 'DESC' ) {
8888
);
8989

9090
if ( $type ) { // use type if set
91-
if ( 'mention' == $type ) {
92-
$args['type__not_in'] = 'comment';
93-
$args['meta_query'] = array(
91+
if ( 'mention' === $type ) {
92+
$args['type__not_in'] = 'comment';
93+
$args['meta_query'] = array(
9494
'relation' => 'OR',
9595
array(
9696
'key' => 'semantic_linkbacks_type',
@@ -105,7 +105,7 @@ function get_linkbacks( $type = null, $post_id = null, $order = 'DESC' ) {
105105
'value' => 'mention',
106106
),
107107
);
108-
} elseif ( 'rsvp' == $type ) {
108+
} elseif ( 'rsvp' === $type ) {
109109
$args['meta_query'] = array(
110110
array(
111111
'key' => 'semantic_linkbacks_type',
@@ -183,7 +183,7 @@ function list_linkbacks( $args, $comments ) {
183183
$fold_at = get_option( 'semantic_linkbacks_facepiles_fold_limit', 8 );
184184

185185
foreach ( $comments as $i => $comment ) {
186-
if ( $fold_at && $i == $fold_at ) {
186+
if ( $fold_at && $i === $fold_at ) {
187187
$classes .= ' additional-facepile';
188188
}
189189

0 commit comments

Comments
 (0)