Skip to content

Commit ed983f6

Browse files
Move exceptions for PHP code style rules into specific lines which should be ignored
1 parent 4d6b1a9 commit ed983f6

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

phpcs.xml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,12 @@
2020

2121
<!-- WordPress coding standards -->
2222
<config name="minimum_supported_wp_version" value="4.7" />
23-
<rule ref="WordPress">
24-
</rule>
25-
<rule ref="WordPress.VIP.DirectDatabaseQuery.NoCaching">
26-
<exclude-pattern>comments.php</exclude-pattern>
27-
<exclude-pattern>posts.php</exclude-pattern>
28-
<exclude-pattern>users.php</exclude-pattern>
29-
</rule>
23+
<rule ref="WordPress" />
3024
<rule ref="WordPress.WP.I18n">
3125
<properties>
3226
<property name="text_domain" type="array" value="posts-and-users-stats" />
3327
</properties>
3428
</rule>
35-
<rule ref="WordPress.WP.PreparedSQL.NotPrepared">
36-
<exclude-pattern>posts.php</exclude-pattern>
37-
</rule>
38-
<rule ref="WordPress.VIP.RestrictedFunctions.count_user_posts_count_user_posts">
39-
<exclude-pattern>posts.php</exclude-pattern>
40-
</rule>
4129

4230
<!-- Include sniffs for PHP cross-version compatibility. -->
4331
<config name="testVersion" value="5.6-"/>

views/comments.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class="<?php posts_and_users_stats_echo_tab_class( $selected_tab == $tab_slug );
3737
<?php
3838
if ( 'date' == $selected_tab ) {
3939
global $wpdb;
40+
// phpcs:disable WordPress.VIP.DirectDatabaseQuery.NoCaching
4041
$comments_per_date = $wpdb->get_results(
4142
"SELECT DATE(comment_date) as date, count(comment_ID) as count
4243
FROM {$wpdb->comments}
@@ -58,6 +59,7 @@ class="<?php posts_and_users_stats_echo_tab_class( $selected_tab == $tab_slug );
5859
GROUP BY year",
5960
OBJECT_K
6061
);
62+
// phpcs:enable WordPress.VIP.DirectDatabaseQuery.NoCaching
6163

6264
$per_date_string = __( 'Comments per Date', 'posts-and-users-stats' );
6365
$per_month_string = __( 'Comments per Month', 'posts-and-users-stats' );
@@ -216,6 +218,7 @@ class="<?php posts_and_users_stats_echo_tab_class( $selected_tab == $tab_slug );
216218
} // end if
217219
} else if ( 'author' == $selected_tab ) {
218220
global $wpdb;
221+
// phpcs:ignore WordPress.VIP.DirectDatabaseQuery.NoCaching
219222
$comments_per_author = $wpdb->get_results(
220223
"SELECT comment_author as author, count(comment_ID) as count
221224
FROM {$wpdb->comments}

views/posts.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ class="<?php posts_and_users_stats_echo_tab_class( $selected_tab == $tab_slug );
7070
}
7171

7272
global $wpdb;
73+
// phpcs:disable WordPress.WP.PreparedSQL.NotPrepared
74+
// phpcs:disable WordPress.VIP.DirectDatabaseQuery.NoCaching
7375
$posts_per_date = $wpdb->get_results(
7476
"SELECT DATE(post_date) as date, count(ID) as count
7577
FROM {$wpdb->posts}
@@ -92,6 +94,8 @@ class="<?php posts_and_users_stats_echo_tab_class( $selected_tab == $tab_slug );
9294
ORDER BY year DESC',
9395
OBJECT_K
9496
);
97+
// phpcs:enable WordPress.WP.PreparedSQL.NotPrepared
98+
// phpcs:enable WordPress.VIP.DirectDatabaseQuery.NoCaching
9599

96100
$per_date_string = sprintf(
97101
// translators: post type.
@@ -404,7 +408,10 @@ class="<?php posts_and_users_stats_echo_tab_class( $selected_tab == $tab_slug );
404408
);
405409
$total = 0;
406410
foreach ( $post_types as $post_type ) {
407-
$count = intval( count_user_posts( $user->ID, $post_type, true ) );
411+
$count = intval(
412+
// phpcs:ignore WordPress.VIP.RestrictedFunctions.count_user_posts_count_user_posts
413+
count_user_posts( $user->ID, $post_type, true )
414+
);
408415
$user_data[ $post_type ] = $count;
409416
$total += $count;
410417
}

views/users.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class="<?php posts_and_users_stats_echo_tab_class( $selected_tab == $tab_slug );
114114
<?php
115115
} else if ( 'date' == $selected_tab ) {
116116
global $wpdb;
117+
// phpcs:ignore WordPress.VIP.DirectDatabaseQuery.NoCaching
117118
$user_registration_dates = $wpdb->get_results(
118119
'SELECT DATE(user_registered) AS date, count(*) as count
119120
FROM ' . $wpdb->prefix . 'users

0 commit comments

Comments
 (0)