Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"wp-cli/entity-command": "^1.2 || ^2",
"wp-cli/extension-command": "^1.1 || ^2",
"wp-cli/package-command": "^1 || ^2",
"wp-cli/wp-cli-tests": "^3.1.6"
"wp-cli/wp-cli-tests": "^4.0.1"
},
"suggest": {
"ext-readline": "Include for a better --prompt implementation",
Expand Down
1 change: 0 additions & 1 deletion php/WP_CLI/Completions.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public function __construct( $line ) {
$this->add( $opt );
}
}

}

/**
Expand Down
1 change: 0 additions & 1 deletion php/WP_CLI/ComposerIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ private static function output_clean_message( $messages ) {
WP_CLI::log( strip_tags( trim( $message ) ) );
}
}

}
1 change: 0 additions & 1 deletion php/WP_CLI/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,5 +393,4 @@ private static function absolutize( &$path, $base ) {
$path = $base . DIRECTORY_SEPARATOR . $path;
}
}

}
19 changes: 15 additions & 4 deletions php/WP_CLI/Dispatcher/CommandFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,29 +213,40 @@ private static function get_doc_comment( $reflection ) {
private static function extract_last_doc_comment( $content ) {
$content = trim( $content );
$comment_end_pos = strrpos( $content, '*/' );

if ( false === $comment_end_pos ) {
return false;
}

// Make sure comment end belongs to this class/function.
if ( preg_match_all( '/(?:^|[\s;}])(?:class|function)\s+/', substr( $content, $comment_end_pos + 2 ), $dummy /*needed for PHP 5.3*/ ) > 1 ) {
return false;
}

$content = substr( $content, 0, $comment_end_pos + 2 );
$comment_start_pos = strrpos( $content, '/**' );

if ( false === $comment_start_pos || ( $comment_start_pos + 2 ) === $comment_end_pos ) {
return false;
}

// Make sure comment start belongs to this comment end.
$comment_end2_pos = strpos( substr( $content, $comment_start_pos ), '*/' );

if ( false !== $comment_end2_pos && ( $comment_start_pos + $comment_end2_pos ) < $comment_end_pos ) {
return false;
}

// Allow for '/**' within doc comment.
$subcontent = substr( $content, 0, $comment_start_pos );
while ( false !== ( $comment_start2_pos = strrpos( $subcontent, '/**' ) ) && false === strpos( $subcontent, '*/', $comment_start2_pos ) ) {
$comment_start_pos = $comment_start2_pos;
$subcontent = substr( $subcontent, 0, $comment_start_pos );
$subcontent = substr( $content, 0, $comment_start_pos );
$comment_start2_pos = strrpos( $subcontent, '/**' );

while ( false !== $comment_start2_pos && false === strpos( $subcontent, '*/', $comment_start2_pos ) ) {
$comment_start_pos = $comment_start2_pos;
$subcontent = substr( $subcontent, 0, $comment_start_pos );
$comment_start2_pos = strrpos( $subcontent, '/**' );
}

return substr( $content, $comment_start_pos, $comment_end_pos + 2 );
}
}
5 changes: 2 additions & 3 deletions php/WP_CLI/Dispatcher/CommandNamespace.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public function show_usage() {

foreach ( $methods as $subcommand ) {
$prefix = ( 0 === $i ) ? 'usage: ' : ' or: ';
$i++;
++$i;

if ( \WP_CLI::get_runner()->is_command_disabled( $subcommand ) ) {
continue;
}

\WP_CLI::line( $subcommand->get_usage( $prefix ) );
$count++;
++$count;
}

$cmd_name = implode( ' ', array_slice( get_path( $this ), 1 ) );
Expand All @@ -46,6 +46,5 @@ public function show_usage() {

\WP_CLI::line();
\WP_CLI::line( $message );

}
}
4 changes: 2 additions & 2 deletions php/WP_CLI/Dispatcher/CompositeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function show_usage() {

foreach ( $methods as $subcommand ) {
$prefix = ( 0 === $i ) ? 'usage: ' : ' or: ';
$i++;
++$i;

if ( WP_CLI::get_runner()->is_command_disabled( $subcommand ) ) {
continue;
Expand All @@ -210,7 +210,7 @@ public function show_usage() {
* @param array $assoc_args
* @param array $extra_args
*/
public function invoke( $args, $assoc_args, $extra_args ) {
public function invoke( $args, $assoc_args, $extra_args ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- arguments not used, as only help displayed.
$this->show_usage();
}

Expand Down
13 changes: 5 additions & 8 deletions php/WP_CLI/Dispatcher/Subcommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private function prompt_args( $args, $assoc_args ) {

$spec = array_filter(
SynopsisParser::parse( $synopsis ),
function( $spec_arg ) use ( $args, $assoc_args, &$arg_index ) {
function ( $spec_arg ) use ( $args, $assoc_args, &$arg_index ) {
switch ( $spec_arg['type'] ) {
case 'positional':
// Only prompt for the positional arguments that are not
Expand Down Expand Up @@ -338,16 +338,13 @@ private function validate_args( $args, $assoc_args, $extra_args ) {
if ( isset( $args[ $i ] ) && ! in_array( $args[ $i ], $spec_args['options'] ) ) {
\WP_CLI::error( 'Invalid value specified for positional arg.' );
}
$i++;
++$i;
} while ( isset( $args[ $i ] ) );
} else {
// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict -- This is a loose comparison by design.
if ( isset( $args[ $i ] ) && ! in_array( $args[ $i ], $spec_args['options'] ) ) {
\WP_CLI::error( 'Invalid value specified for positional arg.' );
}
} elseif ( isset( $args[ $i ] ) && ! in_array( $args[ $i ], $spec_args['options'] ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict -- This is a loose comparison by design.
\WP_CLI::error( 'Invalid value specified for positional arg.' );
}
}
$i++;
++$i;
} elseif ( 'assoc' === $spec['type'] ) {
$spec_args = $docparser->get_param_args( $spec['name'] );
if ( ! isset( $assoc_args[ $spec['name'] ] ) && ! isset( $extra_args[ $spec['name'] ] ) ) {
Expand Down
2 changes: 0 additions & 2 deletions php/WP_CLI/DocParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ public function get_arg_desc( $name ) {
}

return '';

}

/**
Expand Down Expand Up @@ -195,5 +194,4 @@ private function get_arg_or_param_args( $regex ) {
}
return null;
}

}
16 changes: 7 additions & 9 deletions php/WP_CLI/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private static function extract_tarball( $tarball, $dest ) {

$process_run = WP_CLI::launch(
$cmd,
false /*exit_on_error*/,
false, /*exit_on_error*/
true /*return_detailed*/
);

Expand Down Expand Up @@ -187,15 +187,13 @@ public static function copy_overwrite_files( $source, $dest ) {
if ( ! is_dir( $dest_path ) ) {
mkdir( $dest_path );
}
} else {
if ( file_exists( $dest_path ) && is_writable( $dest_path ) ) {
copy( $item, $dest_path );
} elseif ( ! file_exists( $dest_path ) ) {
} elseif ( file_exists( $dest_path ) && is_writable( $dest_path ) ) {
copy( $item, $dest_path );
} else {
$error = 1;
WP_CLI::warning( "Unable to copy '" . $iterator->getSubPathName() . "' to current directory." );
}
} elseif ( ! file_exists( $dest_path ) ) {
copy( $item, $dest_path );
} else {
$error = 1;
WP_CLI::warning( "Unable to copy '" . $iterator->getSubPathName() . "' to current directory." );
}
}

Expand Down
1 change: 0 additions & 1 deletion php/WP_CLI/Fetchers/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,3 @@ public function get_many( $args ) {
return $items;
}
}

1 change: 0 additions & 1 deletion php/WP_CLI/Fetchers/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ public function get( $arg ) {
return $comment;
}
}

1 change: 0 additions & 1 deletion php/WP_CLI/Fetchers/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ public function get( $arg ) {
return $post;
}
}

1 change: 0 additions & 1 deletion php/WP_CLI/Fetchers/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,3 @@ public function get( $arg ) {
return $user;
}
}

1 change: 0 additions & 1 deletion php/WP_CLI/FileCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public function __construct( $cache_dir, $ttl, $max_size, $whitelist = 'a-z0-9._
if ( ! $this->ensure_dir_exists( $this->root ) ) {
$this->enabled = false;
}

}

/**
Expand Down
2 changes: 0 additions & 2 deletions php/WP_CLI/Formatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ private function show_multiple_fields( $data, $format, $ascii_pre_colorized = fa
break;

}

}

/**
Expand Down Expand Up @@ -367,5 +366,4 @@ public function transform_item_values_to_json( $item ) {
}
return $item;
}

}
2 changes: 1 addition & 1 deletion php/WP_CLI/Inflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public static function camelize( $word ) {
public static function ucwords( $string, $delimiters = " \n\t\r\0\x0B-" ) {
return preg_replace_callback(
'/[^' . preg_quote( $delimiters, '/' ) . ']+/',
function( $matches ) {
function ( $matches ) {
return ucfirst( $matches[0] );
},
$string
Expand Down
3 changes: 1 addition & 2 deletions php/WP_CLI/Iterators/CSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function next() {

if ( ! empty( $element ) ) {
$this->current_element = $element;
$this->current_index++;
++$this->current_index;

break;
}
Expand All @@ -88,4 +88,3 @@ public function valid() {
return is_array( $this->current_element );
}
}

1 change: 0 additions & 1 deletion php/WP_CLI/Iterators/Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
use RuntimeException;

class Exception extends RuntimeException {}

5 changes: 2 additions & 3 deletions php/WP_CLI/Iterators/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public function key() {

#[\ReturnTypeWillChange]
public function next() {
$this->index_in_results++;
$this->global_index++;
++$this->index_in_results;
++$this->global_index;
}

#[\ReturnTypeWillChange]
Expand Down Expand Up @@ -134,4 +134,3 @@ public function valid() {
return true;
}
}

1 change: 0 additions & 1 deletion php/WP_CLI/Iterators/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,3 @@ private static function build_where_conditions( $where ) {
return $where;
}
}

1 change: 0 additions & 1 deletion php/WP_CLI/Loggers/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,4 @@ protected function _line( $message, $label, $color, $handle = STDOUT ) { // phpc
}
$this->write( $handle, "$label $message\n" );
}

}
2 changes: 1 addition & 1 deletion php/WP_CLI/Loggers/Regular.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function error( $message ) {
public function error_multi_line( $message_lines ) {
// Convert tabs to four spaces, as some shells will output the tabs as variable-length.
$message_lines = array_map(
function( $line ) {
function ( $line ) {
return str_replace( "\t", ' ', $line );
},
$message_lines
Expand Down
1 change: 0 additions & 1 deletion php/WP_CLI/NoOp.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@ public function __call( $method, $args ) {
// do nothing
}
}

2 changes: 0 additions & 2 deletions php/WP_CLI/PackageManagerEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,5 @@ public static function post_install( PackageEvent $event ) {
WP_CLI::log( sprintf( ' - Warning: %s', $composer_error ) );
}
}

}

}
2 changes: 1 addition & 1 deletion php/WP_CLI/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function run() {
self::$run_times[ $this->command ] = [ 0, 0 ];
}
self::$run_times[ $this->command ][0] += $run_time;
self::$run_times[ $this->command ][1]++;
++self::$run_times[ $this->command ][1];
}

return new ProcessRun(
Expand Down
10 changes: 4 additions & 6 deletions php/WP_CLI/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static function ( $dir ) {
static $wp_load_count = 0;
$wp_load_path = $dir . DIRECTORY_SEPARATOR . 'wp-load.php';
if ( file_exists( $wp_load_path ) ) {
++ $wp_load_count;
++$wp_load_count;
}
return $wp_load_count > 1;
}
Expand Down Expand Up @@ -1277,7 +1277,6 @@ public function start() {
$this->load_wordpress();

$this->run_command_and_exit();

}

/**
Expand Down Expand Up @@ -1362,7 +1361,7 @@ public function load_wordpress() {
}

// Fix memory limit. See https://core.trac.wordpress.org/ticket/14889
// phpcs:ignore WordPress.PHP.IniSet.memory_limit_Blacklisted -- This is perfectly fine for CLI usage.
// phpcs:ignore WordPress.PHP.IniSet.memory_limit_Disallowed -- This is perfectly fine for CLI usage.
ini_set( 'memory_limit', -1 );

// Load all the admin APIs, for convenience
Expand All @@ -1383,7 +1382,6 @@ static function () {

WP_CLI::debug( 'Loaded WordPress', 'bootstrap' );
WP_CLI::do_hook( 'after_wp_load' );

}

private static function fake_current_site_blog( $url_parts ) {
Expand Down Expand Up @@ -1541,7 +1539,7 @@ static function () {
// Use our own debug mode handling instead of WP core
WP_CLI::add_wp_hook(
'enable_wp_debug_mode_checks',
static function ( $ret ) {
static function ( $ret ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- WP core hook.
Utils\wp_debug_mode();
return false;
}
Expand Down Expand Up @@ -1964,6 +1962,6 @@ private function enable_error_reporting() {
// Don't enable E_DEPRECATED as old versions of WP use PHP 4 style constructors and the mysql extension.
error_reporting( E_ALL & ~E_DEPRECATED );
}
ini_set( 'display_errors', 'stderr' ); // phpcs:ignore WordPress.PHP.IniSet.display_errors_Blacklisted
ini_set( 'display_errors', 'stderr' ); // phpcs:ignore WordPress.PHP.IniSet.display_errors_Disallowed
}
}
7 changes: 2 additions & 5 deletions php/WP_CLI/SynopsisValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,11 @@ public function validate_assoc( $assoc_args ) {
if ( ! $param['optional'] ) {
$errors['fatal'][ $key ] = "missing --$key parameter";
}
} else {
if ( true === $assoc_args[ $key ] && ! $param['value']['optional'] ) {
} elseif ( true === $assoc_args[ $key ] && ! $param['value']['optional'] ) {
$error_type = ( ! $param['optional'] ) ? 'fatal' : 'warning';
$errors[ $error_type ][ $key ] = "--$key parameter needs a value";

$to_unset[] = $key;
}
}
}

Expand Down Expand Up @@ -167,7 +165,7 @@ private function query_spec( $args, $operator = 'AND' ) {
$matched = 0;
foreach ( $args as $m_key => $m_value ) {
if ( array_key_exists( $m_key, $to_match ) && $m_value === $to_match[ $m_key ] ) {
$matched++;
++$matched;
}
}

Expand All @@ -180,5 +178,4 @@ private function query_spec( $args, $operator = 'AND' ) {

return $filtered;
}

}
Loading