Skip to content

Commit 9cd5492

Browse files
committed
PHPCS: Update ruleset to exclude NonPrefixedClassFound sniff
Fix CS in find-command
1 parent a1a26be commit 9cd5492

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

find-command.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
return;
55
}
66

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

1212
WP_CLI::add_command( 'find', 'Find_Command' );

phpcs.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@
5151
</properties>
5252
</rule>
5353

54+
<!-- Exclude existing classes from the prefix rule as it would break BC to prefix them now. -->
55+
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedClassFound">
56+
<exclude-pattern>*/src/Find_Command\.php$</exclude-pattern>
57+
</rule>
58+
5459
</ruleset>

src/Find_Command.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use WP_CLI\Utils;
4+
use WP_CLI\Formatter;
45

56
class Find_Command {
67

@@ -9,7 +10,7 @@ class Find_Command {
910
*
1011
* @var array
1112
*/
12-
private $ignored_paths = array(
13+
private $ignored_paths = [
1314
// System directories
1415
'/__MACOSX/',
1516
// Webserver directories
@@ -53,7 +54,7 @@ class Find_Command {
5354
// Already in a WordPress install
5455
'/wp-admin/',
5556
'/wp-content/',
56-
);
57+
];
5758

5859
/**
5960
* Beginning of the recursion path.
@@ -102,14 +103,14 @@ class Find_Command {
102103
*
103104
* @var array
104105
*/
105-
private $resolved_aliases = array();
106+
private $resolved_aliases = [];
106107

107108
/**
108109
* Found WordPress installations.
109110
*
110111
* @var array
111112
*/
112-
private $found_wp = array();
113+
private $found_wp = [];
113114

114115
/**
115116
* Find WordPress installations on the filesystem.
@@ -207,7 +208,7 @@ public function __invoke( $args, $assoc_args ) {
207208
$this->resolved_aliases[ rtrim( $target['path'], '/' ) ] = $alias;
208209
}
209210

210-
$fields = array( 'version_path', 'version', 'depth', 'alias' );
211+
$fields = [ 'version_path', 'version', 'depth', 'alias' ];
211212
if ( ! empty( $assoc_args['fields'] ) ) {
212213
$fields = explode( ',', $assoc_args['fields'] );
213214
}
@@ -216,7 +217,7 @@ public function __invoke( $args, $assoc_args ) {
216217
$this->log( "Searching for WordPress installations in '{$path}'" );
217218
$this->recurse_directory( $this->base_path );
218219
$this->log( "Finished search for WordPress installations in '{$path}'" );
219-
$formatter = new \WP_CLI\Formatter( $assoc_args, $fields );
220+
$formatter = new Formatter( $assoc_args, $fields );
220221
$formatter->display_items( $this->found_wp );
221222
}
222223

@@ -233,7 +234,7 @@ private function recurse_directory( $path ) {
233234
// Don't recurse directories that probably don't have a WordPress installation.
234235
if ( ! $this->skip_ignored_paths ) {
235236
// Assume base path doesn't need comparison
236-
$compared_path = preg_replace( '#^' . preg_quote( $this->base_path ) . '#', '', $path );
237+
$compared_path = preg_replace( '#^' . preg_quote( $this->base_path, '/' ) . '#', '', $path );
237238
// Ignore all hidden system directories
238239
$bits = explode( '/', trim( $compared_path, '/' ) );
239240
$current_dir = array_pop( $bits );
@@ -258,7 +259,7 @@ private function recurse_directory( $path ) {
258259
$alias = isset( $this->resolved_aliases[ $wp_path ] ) ? $this->resolved_aliases[ $wp_path ] : '';
259260
$wp_path = rtrim( $wp_path, '/' ) . '/';
260261

261-
$this->found_wp[ $version_path ] = array(
262+
$this->found_wp[ $version_path ] = [
262263
'version_path' => $version_path,
263264
'version' => self::get_wp_version( $version_path ),
264265
'wp_path' => rtrim( $wp_path, '/' ) . '/',
@@ -267,25 +268,25 @@ private function recurse_directory( $path ) {
267268
'db_host' => '',
268269
'db_name' => '',
269270
'db_user' => '',
270-
);
271+
];
271272

272273
$config_path = self::get_wp_config_path( $wp_path );
273274
if ( $config_path ) {
274275
try {
275276
$transformer = new WPConfigTransformer( $config_path );
276-
foreach ( array( 'db_host', 'db_name', 'db_user' ) as $constant ) {
277+
foreach ( [ 'db_host', 'db_name', 'db_user' ] as $constant ) {
277278
$value = $transformer->get_value( 'constant', strtoupper( $constant ) );
278279
// Clean up strings.
279280
$first = substr( $value, 0, 1 );
280281
$last = substr( $value, -1 );
281-
$both = array_unique( array( $first, $last ) );
282-
if ( in_array( $both, array( array( '"' ), array( "'" ) ), true ) ) {
282+
$both = array_unique( [ $first, $last ] );
283+
if ( in_array( $both, [ [ '"' ], [ "'" ] ], true ) ) {
283284
$value = substr( $value, 1, -1 );
284285
}
285286
$this->found_wp[ $version_path ][ $constant ] = $value;
286287
}
287288
} catch ( Exception $exception ) {
288-
$this->log( "Could not process the 'wp-config.php' transformation: " . $exception->getMessage() );
289+
$this->log( "Could not process the 'wp-config.php' transformation: {$exception->getMessage()}" );
289290
}
290291
}
291292
$this->log( "Found WordPress installation at '{$version_path}'" );

0 commit comments

Comments
 (0)