Skip to content

Commit

Permalink
PHPCS: fix up the code base [4] - multi-line function calls (#79)
Browse files Browse the repository at this point in the history
* PHPCS: fix up the code base [4-a] - multi-line function calls

Fixes relate to the following rules:
* Each argument in a multiline function call should start on a new line.

Single item associative arrays don't need to be multi-line according to WPCS, so changing the array to single-line also fixes the "multiline function call" issue.

* PHPCS: fix up the code base [4-b] - multi-line function calls

Fixes relate to the following rules:
* Each argument in a multiline function call should start on a new line.

* PHPCS: fix up the code base [4-c] - multi-line function calls

Multi-line function calls need to have each argument on a new line.
In a next iteration of this principle, it is expected that a sniff will be introduced  to ban multi-line function call arguments.

With this mind, a number of function calls with multi-line parameters which are  currently already causing errors to be thrown by PHPCS, have been fixed by moving  multi-line function call arguments out of the function call and defining these as a  variable before passing it to the function call.

* PHPCS: fix up the code base [4-d] - multi-line function calls

Fixes relate to the following rules:
* Each argument in a multiline function call should start on a new line.

Note: in the (near?) future, multi-line arguments in function calls will probably be prohibited.
This will impact this code.

The choice for the future is:
* Either change the closures to full-blown methods.
* Declare them before the function call, assign them to a variable and pass the variable to the function call.
  • Loading branch information
jrfnl authored and schlessera committed Apr 21, 2019
1 parent 025efb4 commit beedcd2
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 37 deletions.
27 changes: 18 additions & 9 deletions language-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,30 @@
}
};

WP_CLI::add_command( 'language core', 'Core_Language_Command', array(
'before_invoke' => $wpcli_language_check_requirements )
WP_CLI::add_command(
'language core',
'Core_Language_Command',
array( 'before_invoke' => $wpcli_language_check_requirements )
);

WP_CLI::add_command( 'language plugin', 'Plugin_Language_Command', array(
'before_invoke' => $wpcli_language_check_requirements )
WP_CLI::add_command(
'language plugin',
'Plugin_Language_Command',
array( 'before_invoke' => $wpcli_language_check_requirements )
);

WP_CLI::add_command( 'language theme', 'Theme_Language_Command', array(
'before_invoke' => $wpcli_language_check_requirements )
WP_CLI::add_command(
'language theme',
'Theme_Language_Command',
array( 'before_invoke' => $wpcli_language_check_requirements )
);

WP_CLI::add_hook( 'after_add_command:site', function () {
WP_CLI::add_command( 'site switch-language', 'Site_Switch_Language_Command' );
} );
WP_CLI::add_hook(
'after_add_command:site',
function () {
WP_CLI::add_command( 'site switch-language', 'Site_Switch_Language_Command' );
}
);

if ( class_exists( 'WP_CLI\Dispatcher\CommandNamespace' ) ) {
WP_CLI::add_command( 'language', 'Language_Namespace' );
Expand Down
37 changes: 19 additions & 18 deletions src/Core_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,27 +92,28 @@ public function list_( $args, $assoc_args ) {

$current_locale = get_locale();

$translations = array_map( function( $translation ) use ( $available, $current_locale, $updates ) {
$translation['status'] = 'uninstalled';
if ( in_array( $translation['language'], $available, true ) ) {
$translation['status'] = 'installed';
}
$translations = array_map(
function( $translation ) use ( $available, $current_locale, $updates ) {
$translation['status'] = 'uninstalled';
if ( in_array( $translation['language'], $available, true ) ) {
$translation['status'] = 'installed';
}

if ( $current_locale === $translation['language'] ) {
$translation['status'] = 'active';
}
if ( $current_locale === $translation['language'] ) {
$translation['status'] = 'active';
}

$update = wp_list_filter( $updates, array(
'language' => $translation['language']
) );
if ( $update ) {
$translation['update'] = 'available';
} else {
$translation['update'] = 'none';
}
$update = wp_list_filter( $updates, array( 'language' => $translation['language'] ) );
if ( $update ) {
$translation['update'] = 'available';
} else {
$translation['update'] = 'none';
}

return $translation;
}, $translations );
return $translation;
},
$translations
);

foreach ( $translations as $key => $translation ) {
foreach ( array_keys( $translation ) as $field ) {
Expand Down
5 changes: 3 additions & 2 deletions src/Plugin_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ public function list_( $args, $assoc_args ) {
$translation['status'] = 'active';
}

$update = wp_list_filter( $updates, array(
$filter_args = array(
'language' => $translation['language'],
'type' => 'plugin',
'slug' => $plugin,
) );
);
$update = wp_list_filter( $updates, $filter_args );

$translation['update'] = $update ? 'available' : 'none';

Expand Down
14 changes: 9 additions & 5 deletions src/Theme_Language_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,12 @@ public function list_( $args, $assoc_args ) {
}

if ( $all ) {
$args = array_map( function( $file ){
return \WP_CLI\Utils\get_theme_name( $file );
}, array_keys( wp_get_themes() ) );
$args = array_map(
function( $file ) {
return \WP_CLI\Utils\get_theme_name( $file );
},
array_keys( wp_get_themes() )
);

if ( empty( $args ) ) {
WP_CLI::success( 'No themes installed.' );
Expand All @@ -124,11 +127,12 @@ public function list_( $args, $assoc_args ) {
$translation['status'] = 'active';
}

$update = wp_list_filter( $updates, array(
$filter_args = array(
'language' => $translation['language'],
'type' => 'theme',
'slug' => $theme,
) );
);
$update = wp_list_filter( $updates, $filter_args );

$translation['update'] = $update ? 'available' : 'none';

Expand Down
4 changes: 1 addition & 3 deletions src/WP_CLI/CommandWithTranslation.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ public function update( $args, $assoc_args ) {
}

// Gets the translation data.
$translation = wp_list_filter( $all_languages, array(
'language' => $update->language
) );
$translation = wp_list_filter( $all_languages, array( 'language' => $update->language ) );
$translation = (object) reset( $translation );

$update->Type = ucfirst( $update->type );
Expand Down

0 comments on commit beedcd2

Please sign in to comment.