Skip to content

Commit dbca8df

Browse files
committed
PHPCS: fix up the code base [1] - whitespace & inline control structures
Simple, mostly whitespace related, fixes to make the code comply with the WPCliCS rules. Fixes relate to the following rules: * Use single quoted strings when the string doesn't contain a single quote or variables. * Align the equality operators in assignment blocks. * No space between `else` and `if` for an `elseif`. * One space on the inside of open/close parenthesis when there is content between them. * Associative arrays with more than one item, should be multi-line. * The double arrow in multi-line arrays should be aligned. * Each array item in a multi-line array should be followed by a comma. * When using array indexes, use no space on the inside of the square brackets when the index is a string or integer and use one space on the inside of the square brackets otherwise. * Use tabs for indentation, spaces for inline alignment. * No precision alignment.
1 parent 155a1f4 commit dbca8df

File tree

1 file changed

+74
-69
lines changed

1 file changed

+74
-69
lines changed

src/Scaffold_Command.php

Lines changed: 74 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class Scaffold_Command extends WP_CLI_Command {
6969
public function post_type( $args, $assoc_args ) {
7070

7171
if ( strlen( $args[0] ) > 20 ) {
72-
WP_CLI::error( "Post type slugs cannot exceed 20 characters in length." );
72+
WP_CLI::error( 'Post type slugs cannot exceed 20 characters in length.' );
7373
}
7474

7575
$defaults = array(
@@ -134,7 +134,7 @@ public function taxonomy( $args, $assoc_args ) {
134134

135135
$this->_scaffold( $args[0], $assoc_args, $defaults, '/taxonomies/', array(
136136
'taxonomy.mustache',
137-
'taxonomy_extended.mustache'
137+
'taxonomy_extended.mustache',
138138
) );
139139
}
140140

@@ -186,8 +186,8 @@ private function _scaffold( $slug, $assoc_args, $defaults, $subdir, $templates )
186186
if ( $path = $this->get_output_path( $control_args, $subdir ) ) {
187187
$filename = $path . $slug . '.php';
188188

189-
$force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force' );
190-
$files_written = $this->create_files( array( $filename => $final_output ), $force );
189+
$force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force' );
190+
$files_written = $this->create_files( array( $filename => $final_output ), $force );
191191
$skip_message = "Skipped creating '$filename'.";
192192
$success_message = "Created '$filename'.";
193193
$this->log_whether_files_written( $files_written, $skip_message, $success_message );
@@ -263,12 +263,12 @@ public function block( $args, $assoc_args ) {
263263

264264
$slug = $args[0];
265265
if ( ! preg_match( '/^[a-z][a-z0-9\-]*$/', $slug ) ) {
266-
WP_CLI::error( "Invalid block slug specified. Block slugs can contain only lowercase alphanumeric characters or dashes, and start with a letter." );
266+
WP_CLI::error( 'Invalid block slug specified. Block slugs can contain only lowercase alphanumeric characters or dashes, and start with a letter.' );
267267
}
268268

269269
$defaults = array(
270-
'title' => str_replace( '-', ' ', $slug ),
271-
'category' => 'widgets',
270+
'title' => str_replace( '-', ' ', $slug ),
271+
'category' => 'widgets',
272272
);
273273
$data = $this->extract_args( $assoc_args, $defaults );
274274

@@ -287,21 +287,21 @@ public function block( $args, $assoc_args ) {
287287
'theme' => false,
288288
) );
289289

290-
$data['namespace'] = $control_args['plugin'] ? $control_args['plugin'] : $this->get_theme_name( $control_args['theme'] );
290+
$data['namespace'] = $control_args['plugin'] ? $control_args['plugin'] : $this->get_theme_name( $control_args['theme'] );
291291
$data['machine_name'] = $this->generate_machine_name( $slug );
292-
$data['plugin'] = $control_args['plugin'] ? true : false;
293-
$data['theme'] = ! $data['plugin'];
292+
$data['plugin'] = $control_args['plugin'] ? true : false;
293+
$data['theme'] = ! $data['plugin'];
294294

295-
$block_dir = $this->get_output_path( $control_args, "/blocks" );
295+
$block_dir = $this->get_output_path( $control_args, '/blocks' );
296296
if ( ! $block_dir ) {
297-
WP_CLI::error( "No plugin or theme selected." );
297+
WP_CLI::error( 'No plugin or theme selected.' );
298298
}
299299

300-
$files_written = $this->create_files( array(
301-
"$block_dir/$slug.php" => self::mustache_render( 'block-php.mustache', $data ),
302-
"$block_dir/$slug/index.js" => self::mustache_render( 'block-index-js.mustache', $data ),
300+
$files_written = $this->create_files( array(
301+
"$block_dir/$slug.php" => self::mustache_render( 'block-php.mustache', $data ),
302+
"$block_dir/$slug/index.js" => self::mustache_render( 'block-index-js.mustache', $data ),
303303
"$block_dir/$slug/editor.css" => self::mustache_render( 'block-editor-css.mustache', $data ),
304-
"$block_dir/$slug/style.css" => self::mustache_render( 'block-style-css.mustache', $data ),
304+
"$block_dir/$slug/style.css" => self::mustache_render( 'block-style-css.mustache', $data ),
305305
), $control_args['force'] );
306306
$skip_message = 'All block files were skipped.';
307307
$success_message = "Created block '{$data['title_ucfirst']}'.";
@@ -351,43 +351,43 @@ public function block( $args, $assoc_args ) {
351351
public function _s( $args, $assoc_args ) {
352352

353353
$theme_slug = $args[0];
354-
$theme_path = WP_CONTENT_DIR . "/themes";
355-
$url = "https://underscores.me";
354+
$theme_path = WP_CONTENT_DIR . '/themes';
355+
$url = 'https://underscores.me';
356356
$timeout = 30;
357357

358358
if ( ! preg_match( '/^[a-z_]\w+$/i', str_replace( '-', '_', $theme_slug ) ) ) {
359-
WP_CLI::error( "Invalid theme slug specified. Theme slugs can only contain letters, numbers, underscores and hyphens, and can only start with a letter or underscore." );
359+
WP_CLI::error( 'Invalid theme slug specified. Theme slugs can only contain letters, numbers, underscores and hyphens, and can only start with a letter or underscore.' );
360360
}
361361

362362
$data = wp_parse_args( $assoc_args, array(
363363
'theme_name' => ucfirst( $theme_slug ),
364-
'author' => "Me",
365-
'author_uri' => "",
364+
'author' => 'Me',
365+
'author_uri' => '',
366366
) );
367367

368368
$_s_theme_path = "$theme_path/$data[theme_name]";
369369

370-
if ( $error_msg = $this->check_target_directory( "theme", $_s_theme_path ) ) {
370+
if ( $error_msg = $this->check_target_directory( 'theme', $_s_theme_path ) ) {
371371
WP_CLI::error( "Invalid theme slug specified. {$error_msg}" );
372372
}
373373

374-
$force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force' );
374+
$force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force' );
375375
$should_write_file = $this->prompt_if_files_will_be_overwritten( $_s_theme_path, $force );
376376
if ( ! $should_write_file ) {
377377
WP_CLI::log( 'No files created' );
378378
die;
379379
}
380380

381-
$theme_description = "Custom theme: " . $data['theme_name'] . ", developed by " . $data['author'];
381+
$theme_description = 'Custom theme: ' . $data['theme_name'] . ', developed by ' . $data['author'];
382382

383383
$body = array();
384384
$body['underscoresme_name'] = $data['theme_name'];
385385
$body['underscoresme_slug'] = $theme_slug;
386386
$body['underscoresme_author'] = $data['author'];
387387
$body['underscoresme_author_uri'] = $data['author_uri'];
388388
$body['underscoresme_description'] = $theme_description;
389-
$body['underscoresme_generate_submit'] = "Generate";
390-
$body['underscoresme_generate'] = "1";
389+
$body['underscoresme_generate_submit'] = 'Generate';
390+
$body['underscoresme_generate'] = '1';
391391
if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'sassify' ) ) {
392392
$body['underscoresme_sass'] = 1;
393393
}
@@ -409,7 +409,8 @@ public function _s( $args, $assoc_args ) {
409409
// Workaround to get scaffolding to work within Travis CI.
410410
// See https://github.com/wp-cli/scaffold-command/issues/181
411411
if ( is_wp_error( $response )
412-
&& false !== strpos( $response->get_error_message(), 'gnutls_handshake() failed' ) ) {
412+
&& false !== strpos( $response->get_error_message(), 'gnutls_handshake() failed' )
413+
) {
413414
// Certificate problem, falling back to unsecured request instead.
414415
$alt_url = str_replace( 'https://', 'http://', $url );
415416
WP_CLI::warning( "Secured request to {$url} failed, using {$alt_url} as a fallback." );
@@ -443,7 +444,7 @@ public function _s( $args, $assoc_args ) {
443444

444445
if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'activate' ) ) {
445446
WP_CLI::run_command( array( 'theme', 'activate', $theme_slug ) );
446-
} else if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'enable-network' ) ) {
447+
} elseif ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'enable-network' ) ) {
447448
WP_CLI::run_command( array( 'theme', 'enable', $theme_slug ), array( 'network' => true ) );
448449
}
449450
}
@@ -497,19 +498,19 @@ function child_theme( $args, $assoc_args ) {
497498
WP_CLI::error( "Invalid theme slug specified. The slug cannot be '.' or '..'." );
498499
}
499500

500-
$data = wp_parse_args( $assoc_args, array(
501+
$data = wp_parse_args( $assoc_args, array(
501502
'theme_name' => ucfirst( $theme_slug ),
502-
'author' => "Me",
503-
'author_uri' => "",
504-
'theme_uri' => "",
503+
'author' => 'Me',
504+
'author_uri' => '',
505+
'theme_uri' => '',
505506
) );
506-
$data['slug'] = $theme_slug;
507+
$data['slug'] = $theme_slug;
507508
$data['parent_theme_function_safe'] = str_replace( array( ' ', '-' ), '_', $data['parent_theme'] );
508-
$data['description'] = ucfirst( $data['parent_theme'] ) . " child theme.";
509+
$data['description'] = ucfirst( $data['parent_theme'] ) . ' child theme.';
509510

510-
$theme_dir = WP_CONTENT_DIR . "/themes" . "/$theme_slug";
511+
$theme_dir = WP_CONTENT_DIR . '/themes' . "/$theme_slug";
511512

512-
if ( $error_msg = $this->check_target_directory( "theme", $theme_dir ) ) {
513+
if ( $error_msg = $this->check_target_directory( 'theme', $theme_dir ) ) {
513514
WP_CLI::error( "Invalid theme slug specified. {$error_msg}" );
514515
}
515516

@@ -518,10 +519,10 @@ function child_theme( $args, $assoc_args ) {
518519

519520
$this->maybe_create_themes_dir();
520521

521-
$force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force' );
522-
$files_written = $this->create_files( array(
523-
$theme_style_path => self::mustache_render( 'child_theme.mustache', $data ),
524-
$theme_functions_path => self::mustache_render( 'child_theme_functions.mustache', $data ),
522+
$force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force' );
523+
$files_written = $this->create_files( array(
524+
$theme_style_path => self::mustache_render( 'child_theme.mustache', $data ),
525+
$theme_functions_path => self::mustache_render( 'child_theme_functions.mustache', $data ),
525526
"$theme_dir/.editorconfig" => file_get_contents( self::get_template_path( '.editorconfig' ) ),
526527
), $force );
527528
$skip_message = 'All theme files were skipped.';
@@ -530,7 +531,7 @@ function child_theme( $args, $assoc_args ) {
530531

531532
if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'activate' ) ) {
532533
WP_CLI::run_command( array( 'theme', 'activate', $theme_slug ) );
533-
} else if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'enable-network' ) ) {
534+
} elseif ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'enable-network' ) ) {
534535
WP_CLI::run_command( array( 'theme', 'enable', $theme_slug ), array( 'network' => true ) );
535536
}
536537
}
@@ -651,7 +652,7 @@ function plugin( $args, $assoc_args ) {
651652
'plugin_author' => 'YOUR NAME HERE',
652653
'plugin_author_uri' => 'YOUR SITE HERE',
653654
'plugin_uri' => 'PLUGIN SITE HERE',
654-
'plugin_tested_up_to' => get_bloginfo('version'),
655+
'plugin_tested_up_to' => get_bloginfo( 'version' ),
655656
) );
656657

657658
$data['textdomain'] = $plugin_slug;
@@ -665,22 +666,22 @@ function plugin( $args, $assoc_args ) {
665666
$plugin_dir = WP_PLUGIN_DIR . "/$plugin_slug";
666667
$this->maybe_create_plugins_dir();
667668

668-
if ( $error_msg = $this->check_target_directory( "plugin", $plugin_dir ) ) {
669+
if ( $error_msg = $this->check_target_directory( 'plugin', $plugin_dir ) ) {
669670
WP_CLI::error( "Invalid plugin slug specified. {$error_msg}" );
670671
}
671672
}
672673

673-
$plugin_path = "$plugin_dir/$plugin_slug.php";
674+
$plugin_path = "$plugin_dir/$plugin_slug.php";
674675
$plugin_readme_path = "$plugin_dir/readme.txt";
675676

676-
$force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force' );
677+
$force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force' );
677678
$files_written = $this->create_files( array(
678-
$plugin_path => self::mustache_render( 'plugin.mustache', $data ),
679-
$plugin_readme_path => self::mustache_render( 'plugin-readme.mustache', $data ),
680-
"$plugin_dir/package.json" => self::mustache_render( 'plugin-packages.mustache', $data ),
681-
"$plugin_dir/Gruntfile.js" => self::mustache_render( 'plugin-gruntfile.mustache', $data ),
682-
"$plugin_dir/.gitignore" => self::mustache_render( 'plugin-gitignore.mustache', $data ),
683-
"$plugin_dir/.distignore" => self::mustache_render( 'plugin-distignore.mustache', $data ),
679+
$plugin_path => self::mustache_render( 'plugin.mustache', $data ),
680+
$plugin_readme_path => self::mustache_render( 'plugin-readme.mustache', $data ),
681+
"$plugin_dir/package.json" => self::mustache_render( 'plugin-packages.mustache', $data ),
682+
"$plugin_dir/Gruntfile.js" => self::mustache_render( 'plugin-gruntfile.mustache', $data ),
683+
"$plugin_dir/.gitignore" => self::mustache_render( 'plugin-gitignore.mustache', $data ),
684+
"$plugin_dir/.distignore" => self::mustache_render( 'plugin-distignore.mustache', $data ),
684685
"$plugin_dir/.editorconfig" => file_get_contents( self::get_template_path( '.editorconfig' ) ),
685686
), $force );
686687

@@ -690,13 +691,17 @@ function plugin( $args, $assoc_args ) {
690691

691692
if ( ! \WP_CLI\Utils\get_flag_value( $assoc_args, 'skip-tests' ) ) {
692693
$ci = empty( $assoc_args['ci'] ) ? '' : $assoc_args['ci'];
693-
WP_CLI::run_command( array( 'scaffold', 'plugin-tests', $plugin_slug ), array( 'dir' => $plugin_dir, 'ci' => $ci, 'force' => $force ) );
694+
WP_CLI::run_command( array( 'scaffold', 'plugin-tests', $plugin_slug ), array(
695+
'dir' => $plugin_dir,
696+
'ci' => $ci,
697+
'force' => $force,
698+
) );
694699
}
695700

696701
if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'activate' ) ) {
697702
WP_CLI::run_command( array( 'plugin', 'activate', $plugin_slug ) );
698-
} else if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'activate-network' ) ) {
699-
WP_CLI::run_command( array( 'plugin', 'activate', $plugin_slug), array( 'network' => true ) );
703+
} elseif ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'activate-network' ) ) {
704+
WP_CLI::run_command( array( 'plugin', 'activate', $plugin_slug ), array( 'network' => true ) );
700705
}
701706
}
702707

@@ -850,7 +855,7 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
850855
$package = str_replace( ' ', '_', $name );
851856

852857
$tests_dir = "{$target_dir}/tests";
853-
$bin_dir = "{$target_dir}/bin";
858+
$bin_dir = "{$target_dir}/bin";
854859

855860
$wp_filesystem->mkdir( $tests_dir );
856861
$wp_filesystem->mkdir( $bin_dir );
@@ -873,19 +878,19 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
873878
"{$type}_package" => $package,
874879
);
875880

876-
$force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force' );
881+
$force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force' );
877882
$files_to_create = array(
878883
"$tests_dir/bootstrap.php" => self::mustache_render( "{$type}-bootstrap.mustache", $template_data ),
879884
"$tests_dir/test-sample.php" => self::mustache_render( "{$type}-test-sample.mustache", $template_data ),
880885
);
881886
if ( 'travis' === $assoc_args['ci'] ) {
882-
$files_to_create["{$target_dir}/.travis.yml"] = self::mustache_render( 'plugin-travis.mustache', compact( 'wp_versions_to_test' ) );
883-
} else if ( 'circle' === $assoc_args['ci'] ) {
884-
$files_to_create["{$target_dir}/.circleci/config.yml"] = self::mustache_render( 'plugin-circle.mustache', compact( 'wp_versions_to_test' ) );
885-
} else if ( 'gitlab' === $assoc_args['ci'] ) {
886-
$files_to_create["{$target_dir}/.gitlab-ci.yml"] = self::mustache_render( 'plugin-gitlab.mustache' );
887-
} else if ( 'bitbucket' === $assoc_args['ci'] ) {
888-
$files_to_create["{$target_dir}/bitbucket-pipelines.yml"] = self::mustache_render( 'plugin-bitbucket.mustache' );
887+
$files_to_create[ "{$target_dir}/.travis.yml" ] = self::mustache_render( 'plugin-travis.mustache', compact( 'wp_versions_to_test' ) );
888+
} elseif ( 'circle' === $assoc_args['ci'] ) {
889+
$files_to_create[ "{$target_dir}/.circleci/config.yml" ] = self::mustache_render( 'plugin-circle.mustache', compact( 'wp_versions_to_test' ) );
890+
} elseif ( 'gitlab' === $assoc_args['ci'] ) {
891+
$files_to_create[ "{$target_dir}/.gitlab-ci.yml" ] = self::mustache_render( 'plugin-gitlab.mustache' );
892+
} elseif ( 'bitbucket' === $assoc_args['ci'] ) {
893+
$files_to_create[ "{$target_dir}/bitbucket-pipelines.yml" ] = self::mustache_render( 'plugin-bitbucket.mustache' );
889894
}
890895

891896
$files_written = $this->create_files( $files_to_create, $force );
@@ -897,8 +902,8 @@ private function scaffold_plugin_theme_tests( $args, $assoc_args, $type ) {
897902
);
898903

899904
foreach ( $to_copy as $file => $dir ) {
900-
$file_name = "$dir/$file";
901-
$force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force' );
905+
$file_name = "$dir/$file";
906+
$force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force' );
902907
$should_write_file = $this->prompt_if_files_will_be_overwritten( $file_name, $force );
903908
if ( ! $should_write_file ) {
904909
continue;
@@ -943,7 +948,7 @@ private function check_target_directory( $type, $target_dir ) {
943948

944949
protected function create_files( $files_and_contents, $force ) {
945950
$wp_filesystem = $this->init_wp_filesystem();
946-
$wrote_files = array();
951+
$wrote_files = array();
947952

948953
foreach ( $files_and_contents as $filename => $contents ) {
949954
$should_write_file = $this->prompt_if_files_will_be_overwritten( $filename, $force );
@@ -972,10 +977,10 @@ protected function prompt_if_files_will_be_overwritten( $filename, $force ) {
972977
WP_CLI::log( $filename );
973978
if ( ! $force ) {
974979
do {
975-
$answer = cli\prompt(
980+
$answer = cli\prompt(
976981
'Skip this file, or replace it with scaffolding?',
977982
$default = false,
978-
$marker = '[s/r]: '
983+
$marker = '[s/r]: '
979984
);
980985
} while ( ! in_array( $answer, array( 's', 'r' ) ) );
981986
$should_write_file = 'r' === $answer;
@@ -1108,7 +1113,7 @@ private static function mustache_render( $template, $data = array() ) {
11081113
* Gets the template path based on installation type.
11091114
*/
11101115
private static function get_template_path( $template ) {
1111-
$command_root = Utils\phar_safe_path( dirname( __DIR__ ) );
1116+
$command_root = Utils\phar_safe_path( dirname( __DIR__ ) );
11121117
$template_path = "{$command_root}/templates/{$template}";
11131118

11141119
if ( ! file_exists( $template_path ) ) {

0 commit comments

Comments
 (0)