diff --git a/.distignore b/.distignore index b964b40..95b52fb 100644 --- a/.distignore +++ b/.distignore @@ -6,6 +6,8 @@ .travis.yml behat.yml circle.yml +phpcs.xml.dist +phpunit.xml.dist bin/ features/ utils/ diff --git a/.gitignore b/.gitignore index ff49419..bcf211b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,6 @@ vendor/ *.tar.gz composer.lock *.log +phpunit.xml +phpcs.xml +.phpcs.xml diff --git a/composer.json b/composer.json index 4f66893..a4413ab 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "require-dev": { "behat/behat": "~2.5", - "wp-cli/wp-cli-tests": "^2" + "wp-cli/wp-cli-tests": "^2.1" }, "config": { "platform": { diff --git a/find-command.php b/find-command.php index 6c1e25e..38781ab 100644 --- a/find-command.php +++ b/find-command.php @@ -4,9 +4,9 @@ return; } -$autoload = dirname( __FILE__ ) . '/vendor/autoload.php'; -if ( file_exists( $autoload ) ) { - require_once $autoload; +$wpcli_find_autoloader = dirname( __FILE__ ) . '/vendor/autoload.php'; +if ( file_exists( $wpcli_find_autoloader ) ) { + require_once $wpcli_find_autoloader; } WP_CLI::add_command( 'find', 'Find_Command' ); diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 4252e09..877e832 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -1,61 +1,59 @@ - - Custom ruleset for WP-CLI + + Custom ruleset for WP-CLI find-command + + + + + . - - + + - - . - - */.git/* - */ci/* - */features/* - */packages/* - */tests/* - */utils/* - */vendor/* - - - - - - - - - - - - - - + + - - + + - - - */php/commands/src/CLI_Command.php - + - - - - - - - + - - + + + + + + + - + + + + - + + + + */src/Find_Command\.php$ + + diff --git a/src/Find_Command.php b/src/Find_Command.php index c7abc08..99323db 100644 --- a/src/Find_Command.php +++ b/src/Find_Command.php @@ -1,6 +1,7 @@ resolved_aliases[ rtrim( $target['path'], '/' ) ] = $alias; } - $fields = array( 'version_path', 'version', 'depth', 'alias' ); + $fields = [ 'version_path', 'version', 'depth', 'alias' ]; if ( ! empty( $assoc_args['fields'] ) ) { $fields = explode( ',', $assoc_args['fields'] ); } @@ -216,7 +217,7 @@ public function __invoke( $args, $assoc_args ) { $this->log( "Searching for WordPress installations in '{$path}'" ); $this->recurse_directory( $this->base_path ); $this->log( "Finished search for WordPress installations in '{$path}'" ); - $formatter = new \WP_CLI\Formatter( $assoc_args, $fields ); + $formatter = new Formatter( $assoc_args, $fields ); $formatter->display_items( $this->found_wp ); } @@ -233,7 +234,7 @@ private function recurse_directory( $path ) { // Don't recurse directories that probably don't have a WordPress installation. if ( ! $this->skip_ignored_paths ) { // Assume base path doesn't need comparison - $compared_path = preg_replace( '#^' . preg_quote( $this->base_path ) . '#', '', $path ); + $compared_path = preg_replace( '#^' . preg_quote( $this->base_path, '/' ) . '#', '', $path ); // Ignore all hidden system directories $bits = explode( '/', trim( $compared_path, '/' ) ); $current_dir = array_pop( $bits ); @@ -258,7 +259,7 @@ private function recurse_directory( $path ) { $alias = isset( $this->resolved_aliases[ $wp_path ] ) ? $this->resolved_aliases[ $wp_path ] : ''; $wp_path = rtrim( $wp_path, '/' ) . '/'; - $this->found_wp[ $version_path ] = array( + $this->found_wp[ $version_path ] = [ 'version_path' => $version_path, 'version' => self::get_wp_version( $version_path ), 'wp_path' => rtrim( $wp_path, '/' ) . '/', @@ -267,25 +268,25 @@ private function recurse_directory( $path ) { 'db_host' => '', 'db_name' => '', 'db_user' => '', - ); + ]; $config_path = self::get_wp_config_path( $wp_path ); if ( $config_path ) { try { $transformer = new WPConfigTransformer( $config_path ); - foreach ( array( 'db_host', 'db_name', 'db_user' ) as $constant ) { + foreach ( [ 'db_host', 'db_name', 'db_user' ] as $constant ) { $value = $transformer->get_value( 'constant', strtoupper( $constant ) ); // Clean up strings. $first = substr( $value, 0, 1 ); $last = substr( $value, -1 ); - $both = array_unique( array( $first, $last ) ); - if ( in_array( $both, array( array( '"' ), array( "'" ) ), true ) ) { + $both = array_unique( [ $first, $last ] ); + if ( in_array( $both, [ [ '"' ], [ "'" ] ], true ) ) { $value = substr( $value, 1, -1 ); } $this->found_wp[ $version_path ][ $constant ] = $value; } } catch ( Exception $exception ) { - $this->log( "Could not process the 'wp-config.php' transformation: " . $exception->getMessage() ); + $this->log( "Could not process the 'wp-config.php' transformation: {$exception->getMessage()}" ); } } $this->log( "Found WordPress installation at '{$version_path}'" );