Skip to content

Commit 95f2a07

Browse files
authored
Merge pull request #251 from wp-cli/feature/use-phpcs
Implement CS checking based on the `WP_CLI_CS` ruleset
2 parents 5447cd3 + f6d5a67 commit 95f2a07

36 files changed

+1412
-1072
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

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"wp-cli/db-command": "^1.3 || ^2",
2020
"wp-cli/extension-command": "^1.2 || ^2",
2121
"wp-cli/media-command": "^1.1 || ^2",
22-
"wp-cli/wp-cli-tests": "^2.0.7"
22+
"wp-cli/wp-cli-tests": "^2.1"
2323
},
2424
"config": {
2525
"process-timeout": 7200,

entity-command.php

Lines changed: 59 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,83 @@
44
return;
55
}
66

7-
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
8-
if ( file_exists( $autoload ) ) {
9-
require_once $autoload;
7+
$wpcli_entity_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php';
8+
if ( file_exists( $wpcli_entity_autoloader ) ) {
9+
require_once $wpcli_entity_autoloader;
1010
}
1111

1212
WP_CLI::add_command( 'comment', 'Comment_Command' );
1313
WP_CLI::add_command( 'comment meta', 'Comment_Meta_Command' );
1414
WP_CLI::add_command( 'menu', 'Menu_Command' );
1515
WP_CLI::add_command( 'menu item', 'Menu_Item_Command' );
1616
WP_CLI::add_command( 'menu location', 'Menu_Location_Command' );
17-
WP_CLI::add_command( 'network meta', 'Network_Meta_Command', array(
18-
'before_invoke' => function () {
19-
if ( !is_multisite() ) {
20-
WP_CLI::error( 'This is not a multisite installation.' );
21-
}
22-
}
23-
) );
17+
WP_CLI::add_command(
18+
'network meta',
19+
'Network_Meta_Command',
20+
array(
21+
'before_invoke' => function () {
22+
if ( ! is_multisite() ) {
23+
WP_CLI::error( 'This is not a multisite installation.' );
24+
}
25+
},
26+
)
27+
);
2428
WP_CLI::add_command( 'option', 'Option_Command' );
2529
WP_CLI::add_command( 'post', 'Post_Command' );
2630
WP_CLI::add_command( 'post meta', 'Post_Meta_Command' );
2731
WP_CLI::add_command( 'post term', 'Post_Term_Command' );
2832
WP_CLI::add_command( 'post-type', 'Post_Type_Command' );
2933
WP_CLI::add_command( 'site', 'Site_Command' );
30-
WP_CLI::add_command( 'site meta', 'Site_Meta_Command', array(
31-
'before_invoke' => function() {
32-
if ( !is_multisite() ) {
33-
WP_CLI::error( 'This is not a multisite installation.' );
34-
}
35-
if( ! function_exists('is_site_meta_supported') || ! is_site_meta_supported() ){
36-
WP_CLI::error( sprintf( 'The %s table is not installed. Please run the network database upgrade.', $GLOBALS['wpdb']->blogmeta ) );
37-
}
38-
}
39-
) );
40-
WP_CLI::add_command( 'site option', 'Site_Option_Command', array(
41-
'before_invoke' => function() {
42-
if ( !is_multisite() ) {
43-
WP_CLI::error( 'This is not a multisite installation.' );
44-
}
45-
}
46-
) );
34+
WP_CLI::add_command(
35+
'site meta',
36+
'Site_Meta_Command',
37+
array(
38+
'before_invoke' => function() {
39+
if ( ! is_multisite() ) {
40+
WP_CLI::error( 'This is not a multisite installation.' );
41+
}
42+
if ( ! function_exists( 'is_site_meta_supported' ) || ! is_site_meta_supported() ) {
43+
WP_CLI::error( sprintf( 'The %s table is not installed. Please run the network database upgrade.', $GLOBALS['wpdb']->blogmeta ) );
44+
}
45+
},
46+
)
47+
);
48+
WP_CLI::add_command(
49+
'site option',
50+
'Site_Option_Command',
51+
array(
52+
'before_invoke' => function() {
53+
if ( ! is_multisite() ) {
54+
WP_CLI::error( 'This is not a multisite installation.' );
55+
}
56+
},
57+
)
58+
);
4759
WP_CLI::add_command( 'taxonomy', 'Taxonomy_Command' );
4860
WP_CLI::add_command( 'term', 'Term_Command' );
49-
WP_CLI::add_command( 'term meta', 'Term_Meta_Command', array(
50-
'before_invoke' => function() {
51-
if ( \WP_CLI\Utils\wp_version_compare( '4.4', '<' ) ) {
52-
WP_CLI::error( "Requires WordPress 4.4 or greater." );
53-
}
54-
})
61+
WP_CLI::add_command(
62+
'term meta',
63+
'Term_Meta_Command',
64+
array(
65+
'before_invoke' => function() {
66+
if ( \WP_CLI\Utils\wp_version_compare( '4.4', '<' ) ) {
67+
WP_CLI::error( 'Requires WordPress 4.4 or greater.' );
68+
}
69+
},
70+
)
5571
);
5672
WP_CLI::add_command( 'user', 'User_Command' );
5773
WP_CLI::add_command( 'user meta', 'User_Meta_Command' );
58-
WP_CLI::add_command( 'user session', 'User_Session_Command', array(
59-
'before_invoke' => function() {
60-
if ( \WP_CLI\Utils\wp_version_compare( '4.0', '<' ) ) {
61-
WP_CLI::error( "Requires WordPress 4.0 or greater." );
62-
}
63-
})
74+
WP_CLI::add_command(
75+
'user session',
76+
'User_Session_Command',
77+
array(
78+
'before_invoke' => function() {
79+
if ( \WP_CLI\Utils\wp_version_compare( '4.0', '<' ) ) {
80+
WP_CLI::error( 'Requires WordPress 4.0 or greater.' );
81+
}
82+
},
83+
)
6484
);
6585

6686
WP_CLI::add_command( 'user term', 'User_Term_Command' );

phpcs.xml.dist

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="WP-CLI-entity">
3+
<description>Custom ruleset for WP-CLI entity-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+
<!-- Verify that everything in the global namespace is either namespaced or prefixed.
44+
See: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/wiki/Customizable-sniff-properties#naming-conventions-prefix-everything-in-the-global-namespace -->
45+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
46+
<properties>
47+
<property name="prefixes" type="array">
48+
<element value="WP_CLI\Entity"/><!-- Namespaces. -->
49+
<element value="wpcli_entity"/><!-- Global variables and such. -->
50+
</property>
51+
</properties>
52+
</rule>
53+
54+
<!-- Exclude existing classes from the prefix rule as it would break BC to prefix them now. -->
55+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedNamespaceFound">
56+
<exclude-pattern>*/src/WP_CLI/Fetchers/(Comment|Post|Site|User)\.php$</exclude-pattern>
57+
<exclude-pattern>*/src/WP_CLI/CommandWith(DBObject|Meta|Terms)\.php$</exclude-pattern>
58+
</rule>
59+
60+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound">
61+
<exclude-pattern>*/src/Taxonomy_Command\.php$</exclude-pattern>
62+
<exclude-pattern>*/src/Comment(_Meta)?_Command\.php$</exclude-pattern>
63+
<exclude-pattern>*/src/Menu(_Item|_Location)?_Command\.php$</exclude-pattern>
64+
<exclude-pattern>*/src/Network_Meta_Command\.php$</exclude-pattern>
65+
<exclude-pattern>*/src/Network_Namespace\.php$</exclude-pattern>
66+
<exclude-pattern>*/src/Option_Command\.php$</exclude-pattern>
67+
<exclude-pattern>*/src/Post(_Meta|_Term|_Type)?_Command\.php$</exclude-pattern>
68+
<exclude-pattern>*/src/Site(_Meta|_Option)?_Command\.php$</exclude-pattern>
69+
<exclude-pattern>*/src/Term(_Meta)?_Command\.php$</exclude-pattern>
70+
<exclude-pattern>*/src/User(_Meta|_Session|_Term)?_Command\.php$</exclude-pattern>
71+
</rule>
72+
73+
<!-- Whitelisting to provide backward compatibility to classes possibly extending this class. -->
74+
<rule ref="PSR2.Methods.MethodDeclaration.Underscore">
75+
<exclude-pattern>*/src/WP_CLI/CommandWithDBObject\.php$</exclude-pattern>
76+
</rule>
77+
78+
</ruleset>

0 commit comments

Comments
 (0)