Skip to content

Commit ee2be5a

Browse files
authored
Merge pull request #5834 from wp-cli/fix/wpcs-3.0-issues
2 parents b6ab667 + 1c6590e commit ee2be5a

45 files changed

Lines changed: 98 additions & 139 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"wp-cli/entity-command": "^1.2 || ^2",
2222
"wp-cli/extension-command": "^1.1 || ^2",
2323
"wp-cli/package-command": "^1 || ^2",
24-
"wp-cli/wp-cli-tests": "^3.1.6"
24+
"wp-cli/wp-cli-tests": "^4.0.1"
2525
},
2626
"suggest": {
2727
"ext-readline": "Include for a better --prompt implementation",

php/WP_CLI/Completions.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public function __construct( $line ) {
103103
$this->add( $opt );
104104
}
105105
}
106-
107106
}
108107

109108
/**

php/WP_CLI/ComposerIO.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,4 @@ private static function output_clean_message( $messages ) {
3838
WP_CLI::log( strip_tags( trim( $message ) ) );
3939
}
4040
}
41-
4241
}

php/WP_CLI/Configurator.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,5 +393,4 @@ private static function absolutize( &$path, $base ) {
393393
$path = $base . DIRECTORY_SEPARATOR . $path;
394394
}
395395
}
396-
397396
}

php/WP_CLI/Dispatcher/CommandFactory.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,29 +213,40 @@ private static function get_doc_comment( $reflection ) {
213213
private static function extract_last_doc_comment( $content ) {
214214
$content = trim( $content );
215215
$comment_end_pos = strrpos( $content, '*/' );
216+
216217
if ( false === $comment_end_pos ) {
217218
return false;
218219
}
220+
219221
// Make sure comment end belongs to this class/function.
220222
if ( preg_match_all( '/(?:^|[\s;}])(?:class|function)\s+/', substr( $content, $comment_end_pos + 2 ), $dummy /*needed for PHP 5.3*/ ) > 1 ) {
221223
return false;
222224
}
225+
223226
$content = substr( $content, 0, $comment_end_pos + 2 );
224227
$comment_start_pos = strrpos( $content, '/**' );
228+
225229
if ( false === $comment_start_pos || ( $comment_start_pos + 2 ) === $comment_end_pos ) {
226230
return false;
227231
}
232+
228233
// Make sure comment start belongs to this comment end.
229234
$comment_end2_pos = strpos( substr( $content, $comment_start_pos ), '*/' );
235+
230236
if ( false !== $comment_end2_pos && ( $comment_start_pos + $comment_end2_pos ) < $comment_end_pos ) {
231237
return false;
232238
}
239+
233240
// Allow for '/**' within doc comment.
234-
$subcontent = substr( $content, 0, $comment_start_pos );
235-
while ( false !== ( $comment_start2_pos = strrpos( $subcontent, '/**' ) ) && false === strpos( $subcontent, '*/', $comment_start2_pos ) ) {
236-
$comment_start_pos = $comment_start2_pos;
237-
$subcontent = substr( $subcontent, 0, $comment_start_pos );
241+
$subcontent = substr( $content, 0, $comment_start_pos );
242+
$comment_start2_pos = strrpos( $subcontent, '/**' );
243+
244+
while ( false !== $comment_start2_pos && false === strpos( $subcontent, '*/', $comment_start2_pos ) ) {
245+
$comment_start_pos = $comment_start2_pos;
246+
$subcontent = substr( $subcontent, 0, $comment_start_pos );
247+
$comment_start2_pos = strrpos( $subcontent, '/**' );
238248
}
249+
239250
return substr( $content, $comment_start_pos, $comment_end_pos + 2 );
240251
}
241252
}

php/WP_CLI/Dispatcher/CommandNamespace.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ public function show_usage() {
2929

3030
foreach ( $methods as $subcommand ) {
3131
$prefix = ( 0 === $i ) ? 'usage: ' : ' or: ';
32-
$i++;
32+
++$i;
3333

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

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

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

4747
\WP_CLI::line();
4848
\WP_CLI::line( $message );
49-
5049
}
5150
}

php/WP_CLI/Dispatcher/CompositeCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function show_usage() {
187187

188188
foreach ( $methods as $subcommand ) {
189189
$prefix = ( 0 === $i ) ? 'usage: ' : ' or: ';
190-
$i++;
190+
++$i;
191191

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

php/WP_CLI/Dispatcher/Subcommand.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private function prompt_args( $args, $assoc_args ) {
153153

154154
$spec = array_filter(
155155
SynopsisParser::parse( $synopsis ),
156-
function( $spec_arg ) use ( $args, $assoc_args, &$arg_index ) {
156+
function ( $spec_arg ) use ( $args, $assoc_args, &$arg_index ) {
157157
switch ( $spec_arg['type'] ) {
158158
case 'positional':
159159
// Only prompt for the positional arguments that are not
@@ -338,16 +338,13 @@ private function validate_args( $args, $assoc_args, $extra_args ) {
338338
if ( isset( $args[ $i ] ) && ! in_array( $args[ $i ], $spec_args['options'] ) ) {
339339
\WP_CLI::error( 'Invalid value specified for positional arg.' );
340340
}
341-
$i++;
341+
++$i;
342342
} while ( isset( $args[ $i ] ) );
343-
} else {
344-
// phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict -- This is a loose comparison by design.
345-
if ( isset( $args[ $i ] ) && ! in_array( $args[ $i ], $spec_args['options'] ) ) {
346-
\WP_CLI::error( 'Invalid value specified for positional arg.' );
347-
}
343+
} elseif ( isset( $args[ $i ] ) && ! in_array( $args[ $i ], $spec_args['options'] ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict -- This is a loose comparison by design.
344+
\WP_CLI::error( 'Invalid value specified for positional arg.' );
348345
}
349346
}
350-
$i++;
347+
++$i;
351348
} elseif ( 'assoc' === $spec['type'] ) {
352349
$spec_args = $docparser->get_param_args( $spec['name'] );
353350
if ( ! isset( $assoc_args[ $spec['name'] ] ) && ! isset( $extra_args[ $spec['name'] ] ) ) {

php/WP_CLI/DocParser.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ public function get_arg_desc( $name ) {
118118
}
119119

120120
return '';
121-
122121
}
123122

124123
/**
@@ -195,5 +194,4 @@ private function get_arg_or_param_args( $regex ) {
195194
}
196195
return null;
197196
}
198-
199197
}

php/WP_CLI/Extractor.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private static function extract_tarball( $tarball, $dest ) {
142142

143143
$process_run = WP_CLI::launch(
144144
$cmd,
145-
false /*exit_on_error*/,
145+
false, /*exit_on_error*/
146146
true /*return_detailed*/
147147
);
148148

@@ -187,15 +187,13 @@ public static function copy_overwrite_files( $source, $dest ) {
187187
if ( ! is_dir( $dest_path ) ) {
188188
mkdir( $dest_path );
189189
}
190-
} else {
191-
if ( file_exists( $dest_path ) && is_writable( $dest_path ) ) {
192-
copy( $item, $dest_path );
193-
} elseif ( ! file_exists( $dest_path ) ) {
190+
} elseif ( file_exists( $dest_path ) && is_writable( $dest_path ) ) {
194191
copy( $item, $dest_path );
195-
} else {
196-
$error = 1;
197-
WP_CLI::warning( "Unable to copy '" . $iterator->getSubPathName() . "' to current directory." );
198-
}
192+
} elseif ( ! file_exists( $dest_path ) ) {
193+
copy( $item, $dest_path );
194+
} else {
195+
$error = 1;
196+
WP_CLI::warning( "Unable to copy '" . $iterator->getSubPathName() . "' to current directory." );
199197
}
200198
}
201199

0 commit comments

Comments
 (0)