Skip to content

Commit 56e2a81

Browse files
authored
Merge pull request #54 from jrfnl/feature/use-phpcs
Implement CS checking based on the WPCliCS ruleset
2 parents a7e037f + 77c232d commit 56e2a81

File tree

5 files changed

+78
-5
lines changed

5 files changed

+78
-5
lines changed

.distignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
.travis.yml
77
behat.yml
88
circle.yml
9+
phpcs.xml.dist
10+
phpunit.xml.dist
911
bin/
1012
features/
1113
utils/

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ vendor/
66
*.tar.gz
77
composer.lock
88
*.log
9+
phpunit.xml
10+
phpcs.xml
11+
.phpcs.xml

phpcs.xml.dist

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="WP-CLI-cache">
3+
<description>Custom ruleset for WP-CLI cache-command</description>
4+
5+
<!--
6+
#############################################################################
7+
COMMAND LINE ARGUMENTS
8+
For help understanding this file: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
9+
For help using PHPCS: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage
10+
#############################################################################
11+
-->
12+
13+
<!-- What to scan. -->
14+
<file>.</file>
15+
16+
<!-- Show progress. -->
17+
<arg value="p"/>
18+
19+
<!-- Strip the filepaths down to the relevant bit. -->
20+
<arg name="basepath" value="./"/>
21+
22+
<!-- Check up to 8 files simultaneously. -->
23+
<arg name="parallel" value="8"/>
24+
25+
<!--
26+
#############################################################################
27+
USE THE WP_CLI_CS RULESET
28+
#############################################################################
29+
-->
30+
31+
<rule ref="WP_CLI_CS"/>
32+
33+
<!--
34+
#############################################################################
35+
PROJECT SPECIFIC CONFIGURATION FOR SNIFFS
36+
#############################################################################
37+
-->
38+
39+
<!-- For help understanding the `testVersion` configuration setting:
40+
https://github.com/PHPCompatibility/PHPCompatibility#sniffing-your-code-for-compatibility-with-specific-php-versions -->
41+
<config name="testVersion" value="5.4-"/>
42+
43+
<!-- Make this sniff slightly less finicky. The WP Core default is 40. -->
44+
<rule ref="Generic.Formatting.MultipleStatementAlignment">
45+
<properties>
46+
<property name="maxPadding" value="20"/>
47+
</properties>
48+
</rule>
49+
50+
<!-- Verify that everything in the global namespace is either namespaced or prefixed.
51+
See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#naming-conventions-prefix-everything-in-the-global-namespace -->
52+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
53+
<properties>
54+
<property name="prefixes" type="array">
55+
<element value="WP_CLI\Cache"/><!-- Namespaces. -->
56+
<element value="wpcli_cache"/><!-- Global variables and such. -->
57+
</property>
58+
</properties>
59+
</rule>
60+
61+
<!-- Exclude existing classes from the prefix rule as it would break BC to prefix them now. -->
62+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound">
63+
<exclude-pattern>*/src/(Cache|Transient)_Command\.php$</exclude-pattern>
64+
</rule>
65+
66+
</ruleset>

src/Cache_Command.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public function decr( $args, $assoc_args ) {
129129
*/
130130
public function delete( $args, $assoc_args ) {
131131
list( $key, $group ) = $args;
132-
$result = wp_cache_delete( $key, $group );
132+
$result = wp_cache_delete( $key, $group );
133133

134134
if ( false === $result ) {
135135
WP_CLI::error( 'The object was not deleted.' );
@@ -188,7 +188,7 @@ public function flush( $args, $assoc_args ) {
188188
*/
189189
public function get( $args, $assoc_args ) {
190190
list( $key, $group ) = $args;
191-
$value = wp_cache_get( $key, $group );
191+
$value = wp_cache_get( $key, $group );
192192

193193
if ( false === $value ) {
194194
WP_CLI::error( "Object with key '$key' and group '$group' not found." );

src/Transient_Command.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function set( $args, $assoc_args ) {
177177
* $ wp transient delete --all --network && wp site list --field=url | xargs -n1 -I % wp --url=% transient delete --all
178178
*/
179179
public function delete( $args, $assoc_args ) {
180-
$key = ( ! empty( $args ) ) ? $args[0] : NULL;
180+
$key = ( ! empty( $args ) ) ? $args[0] : null;
181181

182182
$all = Utils\get_flag_value( $assoc_args, 'all' );
183183
$expired = Utils\get_flag_value( $assoc_args, 'expired' );
@@ -201,10 +201,11 @@ public function delete( $args, $assoc_args ) {
201201
WP_CLI::success( 'Transient deleted.' );
202202
} else {
203203
$func = Utils\get_flag_value( $assoc_args, 'network' ) ? 'get_site_transient' : 'get_transient';
204-
if ( $func( $key ) )
204+
if ( $func( $key ) ) {
205205
WP_CLI::error( 'Transient was not deleted even though the transient appears to exist.' );
206-
else
206+
} else {
207207
WP_CLI::warning( 'Transient was not deleted; however, the transient does not appear to exist.' );
208+
}
208209
}
209210
}
210211

@@ -380,6 +381,7 @@ public function list_( $args, $assoc_args ) {
380381
$query = "SELECT `option_name` as `name`, `option_value` as `value` FROM {$wpdb->options} {$where}";
381382
}
382383

384+
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- Prepared properly above.
383385
$results = $wpdb->get_results( $query );
384386

385387
foreach ( $results as $result ) {

0 commit comments

Comments
 (0)