Skip to content

Commit beedcd2

Browse files
jrfnlschlessera
authored andcommitted
PHPCS: fix up the code base [4] - multi-line function calls (#79)
* 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.
1 parent 025efb4 commit beedcd2

5 files changed

+50
-37
lines changed

language-command.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,30 @@
1616
}
1717
};
1818

19-
WP_CLI::add_command( 'language core', 'Core_Language_Command', array(
20-
'before_invoke' => $wpcli_language_check_requirements )
19+
WP_CLI::add_command(
20+
'language core',
21+
'Core_Language_Command',
22+
array( 'before_invoke' => $wpcli_language_check_requirements )
2123
);
2224

23-
WP_CLI::add_command( 'language plugin', 'Plugin_Language_Command', array(
24-
'before_invoke' => $wpcli_language_check_requirements )
25+
WP_CLI::add_command(
26+
'language plugin',
27+
'Plugin_Language_Command',
28+
array( 'before_invoke' => $wpcli_language_check_requirements )
2529
);
2630

27-
WP_CLI::add_command( 'language theme', 'Theme_Language_Command', array(
28-
'before_invoke' => $wpcli_language_check_requirements )
31+
WP_CLI::add_command(
32+
'language theme',
33+
'Theme_Language_Command',
34+
array( 'before_invoke' => $wpcli_language_check_requirements )
2935
);
3036

31-
WP_CLI::add_hook( 'after_add_command:site', function () {
32-
WP_CLI::add_command( 'site switch-language', 'Site_Switch_Language_Command' );
33-
} );
37+
WP_CLI::add_hook(
38+
'after_add_command:site',
39+
function () {
40+
WP_CLI::add_command( 'site switch-language', 'Site_Switch_Language_Command' );
41+
}
42+
);
3443

3544
if ( class_exists( 'WP_CLI\Dispatcher\CommandNamespace' ) ) {
3645
WP_CLI::add_command( 'language', 'Language_Namespace' );

src/Core_Language_Command.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -92,27 +92,28 @@ public function list_( $args, $assoc_args ) {
9292

9393
$current_locale = get_locale();
9494

95-
$translations = array_map( function( $translation ) use ( $available, $current_locale, $updates ) {
96-
$translation['status'] = 'uninstalled';
97-
if ( in_array( $translation['language'], $available, true ) ) {
98-
$translation['status'] = 'installed';
99-
}
95+
$translations = array_map(
96+
function( $translation ) use ( $available, $current_locale, $updates ) {
97+
$translation['status'] = 'uninstalled';
98+
if ( in_array( $translation['language'], $available, true ) ) {
99+
$translation['status'] = 'installed';
100+
}
100101

101-
if ( $current_locale === $translation['language'] ) {
102-
$translation['status'] = 'active';
103-
}
102+
if ( $current_locale === $translation['language'] ) {
103+
$translation['status'] = 'active';
104+
}
104105

105-
$update = wp_list_filter( $updates, array(
106-
'language' => $translation['language']
107-
) );
108-
if ( $update ) {
109-
$translation['update'] = 'available';
110-
} else {
111-
$translation['update'] = 'none';
112-
}
106+
$update = wp_list_filter( $updates, array( 'language' => $translation['language'] ) );
107+
if ( $update ) {
108+
$translation['update'] = 'available';
109+
} else {
110+
$translation['update'] = 'none';
111+
}
113112

114-
return $translation;
115-
}, $translations );
113+
return $translation;
114+
},
115+
$translations
116+
);
116117

117118
foreach ( $translations as $key => $translation ) {
118119
foreach ( array_keys( $translation ) as $field ) {

src/Plugin_Language_Command.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,12 @@ public function list_( $args, $assoc_args ) {
122122
$translation['status'] = 'active';
123123
}
124124

125-
$update = wp_list_filter( $updates, array(
125+
$filter_args = array(
126126
'language' => $translation['language'],
127127
'type' => 'plugin',
128128
'slug' => $plugin,
129-
) );
129+
);
130+
$update = wp_list_filter( $updates, $filter_args );
130131

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

src/Theme_Language_Command.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,12 @@ public function list_( $args, $assoc_args ) {
9797
}
9898

9999
if ( $all ) {
100-
$args = array_map( function( $file ){
101-
return \WP_CLI\Utils\get_theme_name( $file );
102-
}, array_keys( wp_get_themes() ) );
100+
$args = array_map(
101+
function( $file ) {
102+
return \WP_CLI\Utils\get_theme_name( $file );
103+
},
104+
array_keys( wp_get_themes() )
105+
);
103106

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

127-
$update = wp_list_filter( $updates, array(
130+
$filter_args = array(
128131
'language' => $translation['language'],
129132
'type' => 'theme',
130133
'slug' => $theme,
131-
) );
134+
);
135+
$update = wp_list_filter( $updates, $filter_args );
132136

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

src/WP_CLI/CommandWithTranslation.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ public function update( $args, $assoc_args ) {
6666
}
6767

6868
// Gets the translation data.
69-
$translation = wp_list_filter( $all_languages, array(
70-
'language' => $update->language
71-
) );
69+
$translation = wp_list_filter( $all_languages, array( 'language' => $update->language ) );
7270
$translation = (object) reset( $translation );
7371

7472
$update->Type = ucfirst( $update->type );

0 commit comments

Comments
 (0)