Skip to content

Commit f8153d1

Browse files
authored
Merge pull request #215 from jrfnl/feature/cs-fixes-5
PHPCS: fix up the code base [5] - multi-line function calls
2 parents 6932dc3 + d45ba66 commit f8153d1

File tree

1 file changed

+41
-28
lines changed

1 file changed

+41
-28
lines changed

src/Scaffold_Command.php

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ public function post_type( $args, $assoc_args ) {
7777
'dashicon' => 'admin-post',
7878
);
7979

80-
$this->_scaffold( $args[0], $assoc_args, $defaults, '/post-types/', array(
80+
$templates = array(
8181
'post_type.mustache',
8282
'post_type_extended.mustache',
83-
) );
83+
);
84+
85+
$this->_scaffold( $args[0], $assoc_args, $defaults, '/post-types/', $templates );
8486
}
8587

8688
/**
@@ -132,21 +134,24 @@ public function taxonomy( $args, $assoc_args ) {
132134
$assoc_args['post_types'] = $this->quote_comma_list_elements( $assoc_args['post_types'] );
133135
}
134136

135-
$this->_scaffold( $args[0], $assoc_args, $defaults, '/taxonomies/', array(
137+
$templates = array(
136138
'taxonomy.mustache',
137139
'taxonomy_extended.mustache',
138-
) );
140+
);
141+
142+
$this->_scaffold( $args[0], $assoc_args, $defaults, '/taxonomies/', $templates );
139143
}
140144

141145
private function _scaffold( $slug, $assoc_args, $defaults, $subdir, $templates ) {
142146
$wp_filesystem = $this->init_wp_filesystem();
143147

144-
$control_args = $this->extract_args( $assoc_args, array(
148+
$control_defaults = array(
145149
'label' => preg_replace( '/_|-/', ' ', strtolower( $slug ) ),
146150
'theme' => false,
147151
'plugin' => false,
148152
'raw' => false,
149-
) );
153+
);
154+
$control_args = $this->extract_args( $assoc_args, $control_defaults );
150155

151156
$vars = $this->extract_args( $assoc_args, $defaults );
152157

@@ -280,11 +285,12 @@ public function block( $args, $assoc_args ) {
280285
$data['dashicon'] = $dashicon;
281286
}
282287

283-
$control_args = $this->extract_args( $assoc_args, array(
288+
$control_defaults = array(
284289
'force' => false,
285290
'plugin' => false,
286291
'theme' => false,
287-
) );
292+
);
293+
$control_args = $this->extract_args( $assoc_args, $control_defaults );
288294

289295
$data['namespace'] = $control_args['plugin'] ? $control_args['plugin'] : $this->get_theme_name( $control_args['theme'] );
290296
$data['machine_name'] = $this->generate_machine_name( $slug );
@@ -296,12 +302,13 @@ public function block( $args, $assoc_args ) {
296302
WP_CLI::error( 'No plugin or theme selected.' );
297303
}
298304

299-
$files_written = $this->create_files( array(
305+
$files_to_create = array(
300306
"{$block_dir}/{$slug}.php" => self::mustache_render( 'block-php.mustache', $data ),
301307
"{$block_dir}/{$slug}/index.js" => self::mustache_render( 'block-index-js.mustache', $data ),
302308
"{$block_dir}/{$slug}/editor.css" => self::mustache_render( 'block-editor-css.mustache', $data ),
303309
"{$block_dir}/{$slug}/style.css" => self::mustache_render( 'block-style-css.mustache', $data ),
304-
), $control_args['force'] );
310+
);
311+
$files_written = $this->create_files( $files_to_create, $control_args['force'] );
305312
$skip_message = 'All block files were skipped.';
306313
$success_message = "Created block '{$data['title_ucfirst']}'.";
307314
$this->log_whether_files_written( $files_written, $skip_message, $success_message );
@@ -358,11 +365,12 @@ public function _s( $args, $assoc_args ) {
358365
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.' );
359366
}
360367

361-
$data = wp_parse_args( $assoc_args, array(
368+
$defaults = array(
362369
'theme_name' => ucfirst( $theme_slug ),
363370
'author' => 'Me',
364371
'author_uri' => '',
365-
) );
372+
);
373+
$data = wp_parse_args( $assoc_args, $defaults );
366374

367375
$_s_theme_path = "$theme_path/$data[theme_name]";
368376

@@ -434,9 +442,10 @@ public function _s( $args, $assoc_args ) {
434442
unlink( $tmpfname );
435443

436444
if ( true === $unzip_result ) {
437-
$this->create_files( array(
445+
$files_to_create = array(
438446
"{$theme_path}/{$theme_slug}/.editorconfig" => file_get_contents( self::get_template_path( '.editorconfig' ) ),
439-
), false );
447+
);
448+
$this->create_files( $files_to_create, false );
440449
WP_CLI::success( "Created theme '{$data['theme_name']}'." );
441450
} else {
442451
WP_CLI::error( "Could not decompress your theme files ('{$tmpfname}') at '{$theme_path}': {$unzip_result->get_error_message()}" );
@@ -498,13 +507,14 @@ public function child_theme( $args, $assoc_args ) {
498507
WP_CLI::error( "Invalid theme slug specified. The slug cannot be '.' or '..'." );
499508
}
500509

501-
$data = wp_parse_args( $assoc_args, array(
510+
$defaults = array(
502511
'theme_name' => ucfirst( $theme_slug ),
503512
'author' => 'Me',
504513
'author_uri' => '',
505514
'theme_uri' => '',
506-
) );
515+
);
507516

517+
$data = wp_parse_args( $assoc_args, $defaults );
508518
$data['slug'] = $theme_slug;
509519
$data['parent_theme_function_safe'] = str_replace( array( ' ', '-' ), '_', $data['parent_theme'] );
510520
$data['description'] = ucfirst( $data['parent_theme'] ) . ' child theme.';
@@ -521,12 +531,13 @@ public function child_theme( $args, $assoc_args ) {
521531

522532
$this->maybe_create_themes_dir();
523533

524-
$force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force' );
525-
$files_written = $this->create_files( array(
534+
$files_to_create = array(
526535
$theme_style_path => self::mustache_render( 'child_theme.mustache', $data ),
527536
$theme_functions_path => self::mustache_render( 'child_theme_functions.mustache', $data ),
528537
"{$theme_dir}/.editorconfig" => file_get_contents( self::get_template_path( '.editorconfig' ) ),
529-
), $force );
538+
);
539+
$force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force' );
540+
$files_written = $this->create_files( $files_to_create, $force );
530541
$skip_message = 'All theme files were skipped.';
531542
$success_message = "Created '{$theme_dir}'.";
532543
$this->log_whether_files_written( $files_written, $skip_message, $success_message );
@@ -646,7 +657,7 @@ public function plugin( $args, $assoc_args ) {
646657
WP_CLI::error( "Invalid plugin slug specified. The slug cannot be '.' or '..'." );
647658
}
648659

649-
$data = wp_parse_args( $assoc_args, array(
660+
$defaults = array(
650661
'plugin_slug' => $plugin_slug,
651662
'plugin_name' => $plugin_name,
652663
'plugin_package' => $plugin_package,
@@ -655,7 +666,8 @@ public function plugin( $args, $assoc_args ) {
655666
'plugin_author_uri' => 'YOUR SITE HERE',
656667
'plugin_uri' => 'PLUGIN SITE HERE',
657668
'plugin_tested_up_to' => get_bloginfo( 'version' ),
658-
) );
669+
);
670+
$data = wp_parse_args( $assoc_args, $defaults );
659671

660672
$data['textdomain'] = $plugin_slug;
661673

@@ -677,28 +689,29 @@ public function plugin( $args, $assoc_args ) {
677689
$plugin_path = "{$plugin_dir}/{$plugin_slug}.php";
678690
$plugin_readme_path = "{$plugin_dir}/readme.txt";
679691

680-
$force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force' );
681-
$files_written = $this->create_files( array(
692+
$files_to_create = array(
682693
$plugin_path => self::mustache_render( 'plugin.mustache', $data ),
683694
$plugin_readme_path => self::mustache_render( 'plugin-readme.mustache', $data ),
684695
"{$plugin_dir}/package.json" => self::mustache_render( 'plugin-packages.mustache', $data ),
685696
"{$plugin_dir}/Gruntfile.js" => self::mustache_render( 'plugin-gruntfile.mustache', $data ),
686697
"{$plugin_dir}/.gitignore" => self::mustache_render( 'plugin-gitignore.mustache', $data ),
687698
"{$plugin_dir}/.distignore" => self::mustache_render( 'plugin-distignore.mustache', $data ),
688699
"{$plugin_dir}/.editorconfig" => file_get_contents( self::get_template_path( '.editorconfig' ) ),
689-
), $force );
700+
);
701+
$force = \WP_CLI\Utils\get_flag_value( $assoc_args, 'force' );
702+
$files_written = $this->create_files( $files_to_create, $force );
690703

691704
$skip_message = 'All plugin files were skipped.';
692705
$success_message = 'Created plugin files.';
693706
$this->log_whether_files_written( $files_written, $skip_message, $success_message );
694707

695708
if ( ! \WP_CLI\Utils\get_flag_value( $assoc_args, 'skip-tests' ) ) {
696-
$ci = empty( $assoc_args['ci'] ) ? '' : $assoc_args['ci'];
697-
WP_CLI::run_command( array( 'scaffold', 'plugin-tests', $plugin_slug ), array(
709+
$command_args = array(
698710
'dir' => $plugin_dir,
699-
'ci' => $ci,
711+
'ci' => empty( $assoc_args['ci'] ) ? '' : $assoc_args['ci'],
700712
'force' => $force,
701-
) );
713+
);
714+
WP_CLI::run_command( array( 'scaffold', 'plugin-tests', $plugin_slug ), $command_args );
702715
}
703716

704717
if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'activate' ) ) {

0 commit comments

Comments
 (0)