Skip to content

Commit 7087a84

Browse files
committed
PHPCS: Update ruleset to exclude classes from PrefixAllGlobals.NonPrefixedClassFound sniff
Fix CS in Taxonomy command
1 parent 9676531 commit 7087a84

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

phpcs.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
</rule>
5959

6060
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound">
61+
<exclude-pattern>*/src/Taxonomy_Command\.php$</exclude-pattern>
6162
<exclude-pattern>*/src/Comment(_Meta)?_Command\.php$</exclude-pattern>
6263
<exclude-pattern>*/src/Menu(_Item|_Location)?_Command\.php$</exclude-pattern>
6364
<exclude-pattern>*/src/Network_Meta_Command\.php$</exclude-pattern>

src/Taxonomy_Command.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ protected function get_counts( $taxonomies ) {
5757
return [];
5858
}
5959

60-
$query = $wpdb->prepare(
60+
$query = $wpdb->prepare(
6161
"SELECT `taxonomy`, COUNT(*) AS `count`
6262
FROM $wpdb->term_taxonomy
63-
WHERE `taxonomy` IN (" . implode( ',', array_fill( 0, count( $taxonomies ), '%s' ) ) . ")
64-
GROUP BY `taxonomy`",
63+
WHERE `taxonomy` IN (" . implode( ',', array_fill( 0, count( $taxonomies ), '%s' ) ) . ')
64+
GROUP BY `taxonomy`',
6565
$taxonomies
6666
);
67+
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- $query is already prepared above.
6768
$counts = $wpdb->get_results( $query );
6869

6970
// Make sure there's a count for every item.
@@ -155,11 +156,14 @@ public function list_( $args, $assoc_args ) {
155156
$counts = $this->get_counts( wp_list_pluck( $taxonomies, 'name' ) );
156157
}
157158

158-
$taxonomies = array_map( function( $taxonomy ) use ( $counts ) {
159-
$taxonomy->object_type = implode( ', ', $taxonomy->object_type );
160-
$taxonomy->count = isset( $counts[ $taxonomy->name ] ) ? $counts[ $taxonomy->name ] : 0;
161-
return $taxonomy;
162-
}, $taxonomies );
159+
$taxonomies = array_map(
160+
function( $taxonomy ) use ( $counts ) {
161+
$taxonomy->object_type = implode( ', ', $taxonomy->object_type );
162+
$taxonomy->count = isset( $counts[ $taxonomy->name ] ) ? $counts[ $taxonomy->name ] : 0;
163+
return $taxonomy;
164+
},
165+
$taxonomies
166+
);
163167

164168
$formatter->display_items( $taxonomies );
165169
}
@@ -231,10 +235,13 @@ public function get( $args, $assoc_args ) {
231235
}
232236

233237
if ( empty( $assoc_args['fields'] ) ) {
234-
$default_fields = array_merge( $this->fields, array(
235-
'labels',
236-
'cap'
237-
) );
238+
$default_fields = array_merge(
239+
$this->fields,
240+
array(
241+
'labels',
242+
'cap',
243+
)
244+
);
238245

239246
$assoc_args['fields'] = $default_fields;
240247
}

0 commit comments

Comments
 (0)