Skip to content

Commit 58dd01e

Browse files
authored
Merge pull request #75 from jrfnl/feature/cs-fixes-1
PHPCS: fix up the code base [1] - various small fixes
2 parents 15ff5fd + 5d39b6d commit 58dd01e

7 files changed

+53
-43
lines changed

language-command.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,23 @@
1313
WP_CLI::add_command( 'language core', 'Core_Language_Command', array(
1414
'before_invoke' => function() {
1515
if ( \WP_CLI\Utils\wp_version_compare( '4.0', '<' ) ) {
16-
WP_CLI::error( "Requires WordPress 4.0 or greater." );
16+
WP_CLI::error( 'Requires WordPress 4.0 or greater.' );
1717
}
1818
})
1919
);
2020

2121
WP_CLI::add_command( 'language plugin', 'Plugin_Language_Command', array(
2222
'before_invoke' => function() {
2323
if ( \WP_CLI\Utils\wp_version_compare( '4.0', '<' ) ) {
24-
WP_CLI::error( "Requires WordPress 4.0 or greater." );
24+
WP_CLI::error( 'Requires WordPress 4.0 or greater.' );
2525
}
2626
})
2727
);
2828

2929
WP_CLI::add_command( 'language theme', 'Theme_Language_Command', array(
3030
'before_invoke' => function() {
3131
if ( \WP_CLI\Utils\wp_version_compare( '4.0', '<' ) ) {
32-
WP_CLI::error( "Requires WordPress 4.0 or greater." );
32+
WP_CLI::error( 'Requires WordPress 4.0 or greater.' );
3333
}
3434
})
3535
);

src/Core_Language_Command.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ public function list_( $args, $assoc_args ) {
110110
return $translation;
111111
}, $translations );
112112

113-
foreach( $translations as $key => $translation ) {
114-
foreach( array_keys( $translation ) as $field ) {
113+
foreach ( $translations as $key => $translation ) {
114+
foreach ( array_keys( $translation ) as $field ) {
115115
if ( isset( $assoc_args[ $field ] ) && $assoc_args[ $field ] !== $translation[ $field ] ) {
116116
unset( $translations[ $key ] );
117117
}
@@ -143,7 +143,7 @@ public function list_( $args, $assoc_args ) {
143143
*/
144144
public function is_installed( $args, $assoc_args = array() ) {
145145
list( $language_code ) = $args;
146-
$available = $this->get_installed_languages();
146+
$available = $this->get_installed_languages();
147147
if ( in_array( $language_code, $available, true ) ) {
148148
\WP_CLI::halt( 0 );
149149
} else {
@@ -187,7 +187,9 @@ public function install( $args, $assoc_args ) {
187187

188188
$available = $this->get_installed_languages();
189189

190-
$successes = $errors = $skips = 0;
190+
$successes = 0;
191+
$errors = 0;
192+
$skips = 0;
191193
foreach ( $language_codes as $language_code ) {
192194

193195
if ( in_array( $language_code, $available, true ) ) {
@@ -243,13 +245,13 @@ public function uninstall( $args, $assoc_args ) {
243245

244246
$available = $this->get_installed_languages();
245247

246-
foreach ($language_codes as $language_code) {
248+
foreach ( $language_codes as $language_code ) {
247249

248250
if ( ! in_array( $language_code, $available, true ) ) {
249251
WP_CLI::error( 'Language not installed.' );
250252
}
251253

252-
$dir = 'core' === $this->obj_type ? '' : "/$this->obj_type";
254+
$dir = 'core' === $this->obj_type ? '' : "/$this->obj_type";
253255
$files = scandir( WP_LANG_DIR . $dir );
254256
if ( ! $files ) {
255257
WP_CLI::error( 'No files found in language directory.' );
@@ -269,12 +271,12 @@ public function uninstall( $args, $assoc_args ) {
269271
continue;
270272
}
271273
$extension_length = strlen( $language_code ) + 4;
272-
$ending = substr( $file, -$extension_length );
274+
$ending = substr( $file, -$extension_length );
273275
if ( ! in_array( $file, array( $language_code . '.po', $language_code . '.mo' ), true ) && ! in_array( $ending, array( '-' . $language_code . '.po', '-' . $language_code . '.mo' ), true ) ) {
274276
continue;
275277
}
276278

277-
/* @var WP_Filesystem_Base $wp_filesystem */
279+
/** @var WP_Filesystem_Base $wp_filesystem */
278280
$deleted = $wp_filesystem->delete( WP_LANG_DIR . $dir . '/' . $file );
279281
}
280282

@@ -339,11 +341,11 @@ private function activate_language( $language_code ) {
339341
WP_CLI::error( 'Language not installed.' );
340342
}
341343

342-
if ( $language_code === 'en_US' ) {
344+
if ( 'en_US' === $language_code ) {
343345
$language_code = '';
344346
}
345347

346-
if ( $language_code === get_locale() ) {
348+
if ( get_locale() === $language_code ) {
347349
WP_CLI::warning( "Language '{$language_code}' already active." );
348350

349351
return;

src/Plugin_Language_Command.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function list_( $args, $assoc_args ) {
131131
$translation['update'] = $update ? 'available' : 'none';
132132

133133
// Support features like --status=active.
134-
foreach( array_keys( $translation ) as $field ) {
134+
foreach ( array_keys( $translation ) as $field ) {
135135
if ( isset( $assoc_args[ $field ] ) && $assoc_args[ $field ] !== $translation[ $field ] ) {
136136
continue 2;
137137
}
@@ -249,7 +249,9 @@ private function install_one( $args, $assoc_args ) {
249249

250250
$available = $this->get_installed_languages( $plugin );
251251

252-
$successes = $errors = $skips = 0;
252+
$successes = 0;
253+
$errors = 0;
254+
$skips = 0;
253255
foreach ( $language_codes as $language_code ) {
254256

255257
if ( in_array( $language_code, $available, true ) ) {
@@ -293,7 +295,7 @@ private function install_many( $args, $assoc_args ) {
293295
}
294296

295297
if ( in_array( $assoc_args['format'], array( 'json', 'csv' ) ) ) {
296-
$logger = new \WP_CLI\Loggers\Quiet;
298+
$logger = new \WP_CLI\Loggers\Quiet();
297299
\WP_CLI::set_logger( $logger );
298300
}
299301

@@ -306,7 +308,9 @@ private function install_many( $args, $assoc_args ) {
306308

307309
$results = array();
308310

309-
$successes = $errors = $skips = 0;
311+
$successes = 0;
312+
$errors = 0;
313+
$skips = 0;
310314
foreach ( $plugins as $plugin_path => $plugin_details ) {
311315
$plugin_name = \WP_CLI\Utils\get_plugin_name( $plugin_path );
312316

@@ -373,7 +377,7 @@ private function install_many( $args, $assoc_args ) {
373377
* @subcommand uninstall
374378
*/
375379
public function uninstall( $args, $assoc_args ) {
376-
/* @var WP_Filesystem_Base $wp_filesystem */
380+
/** @var WP_Filesystem_Base $wp_filesystem */
377381
global $wp_filesystem;
378382

379383
$plugin = array_shift( $args );

src/Site_Switch_Language_Command.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ public function __invoke( $args, $assoc_args ) {
2727
WP_CLI::error( 'Language not installed.' );
2828
}
2929

30-
if ( $language_code === 'en_US' ) {
30+
if ( 'en_US' === $language_code ) {
3131
$language_code = '';
3232
}
3333

34-
if ( $language_code === get_locale() ) {
34+
if ( get_locale() === $language_code ) {
3535
WP_CLI::warning( "Language '{$language_code}' already active." );
3636

3737
return;

src/Theme_Language_Command.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function list_( $args, $assoc_args ) {
117117
$available_translations = $this->get_all_languages( $theme );
118118

119119
foreach ( $available_translations as $translation ) {
120-
$translation['theme'] = $theme;
120+
$translation['theme'] = $theme;
121121
$translation['status'] = in_array( $translation['language'], $installed_translations, true ) ? 'installed' : 'uninstalled';
122122

123123
if ( $current_locale === $translation['language'] ) {
@@ -133,7 +133,7 @@ public function list_( $args, $assoc_args ) {
133133
$translation['update'] = $update ? 'available' : 'none';
134134

135135
// Support features like --status=active.
136-
foreach( array_keys( $translation ) as $field ) {
136+
foreach ( array_keys( $translation ) as $field ) {
137137
if ( isset( $assoc_args[ $field ] ) && $assoc_args[ $field ] !== $translation[ $field ] ) {
138138
continue 2;
139139
}
@@ -251,7 +251,9 @@ private function install_one( $args, $assoc_args ) {
251251

252252
$available = $this->get_installed_languages( $theme );
253253

254-
$successes = $errors = $skips = 0;
254+
$successes = 0;
255+
$errors = 0;
256+
$skips = 0;
255257
foreach ( $language_codes as $language_code ) {
256258

257259
if ( in_array( $language_code, $available, true ) ) {
@@ -295,7 +297,7 @@ private function install_many( $args, $assoc_args ) {
295297
}
296298

297299
if ( in_array( $assoc_args['format'], array( 'json', 'csv' ) ) ) {
298-
$logger = new \WP_CLI\Loggers\Quiet;
300+
$logger = new \WP_CLI\Loggers\Quiet();
299301
\WP_CLI::set_logger( $logger );
300302
}
301303

@@ -308,7 +310,9 @@ private function install_many( $args, $assoc_args ) {
308310

309311
$results = array();
310312

311-
$successes = $errors = $skips = 0;
313+
$successes = 0;
314+
$errors = 0;
315+
$skips = 0;
312316
foreach ( $themes as $theme_path => $theme_details ) {
313317
$theme_name = \WP_CLI\Utils\get_theme_name( $theme_path );
314318

@@ -375,7 +379,7 @@ private function install_many( $args, $assoc_args ) {
375379
* @subcommand uninstall
376380
*/
377381
public function uninstall( $args, $assoc_args ) {
378-
/* @var WP_Filesystem_Base $wp_filesystem */
382+
/** @var WP_Filesystem_Base $wp_filesystem */
379383
global $wp_filesystem;
380384

381385
$theme = array_shift( $args );

src/WP_CLI/CommandWithTranslation.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function update( $args, $assoc_args ) {
3838
$args = array( null ); // Used for core.
3939
}
4040

41-
$upgrader = 'WP_CLI\\LanguagePackUpgrader';
42-
$results = array();
41+
$upgrader = 'WP_CLI\\LanguagePackUpgrader';
42+
$results = array();
4343
$num_to_update = 0;
4444

4545
foreach ( $args as $slug ) {
@@ -57,12 +57,12 @@ public function update( $args, $assoc_args ) {
5757
$name = 'WordPress'; // Core.
5858

5959
if ( 'plugin' === $update->type ) {
60-
$plugins = get_plugins( '/' . $update->slug );
60+
$plugins = get_plugins( '/' . $update->slug );
6161
$plugin_data = array_shift( $plugins );
62-
$name = $plugin_data['Name'];
62+
$name = $plugin_data['Name'];
6363
} elseif ( 'theme' === $update->type ) {
64-
$theme_data = wp_get_theme( $update->slug );
65-
$name = $theme_data['Name'];
64+
$theme_data = wp_get_theme( $update->slug );
65+
$name = $theme_data['Name'];
6666
}
6767

6868
// Gets the translation data.
@@ -129,7 +129,7 @@ public function update( $args, $assoc_args ) {
129129

130130
if ( $num_to_update === $num_updated ) {
131131
WP_CLI::success( $line );
132-
} else if ( $num_updated > 0 ) {
132+
} elseif ( $num_updated > 0 ) {
133133
WP_CLI::warning( $line );
134134
} else {
135135
WP_CLI::error( $line );
@@ -150,7 +150,7 @@ protected function get_translation_updates() {
150150
return $available;
151151
};
152152

153-
switch( $this->obj_type ) {
153+
switch ( $this->obj_type ) {
154154
case 'plugins':
155155
add_filter( 'plugins_update_check_locales', $func );
156156

@@ -207,7 +207,7 @@ protected function get_translation_updates() {
207207
* @return string|\WP_Error Returns the language code if successfully downloaded, or a WP_Error object on failure.
208208
*/
209209
protected function download_language_pack( $download, $slug = null ) {
210-
$translations = $this->get_all_languages( $slug );
210+
$translations = $this->get_all_languages( $slug );
211211
$translation_to_load = null;
212212

213213
foreach ( $translations as $translation ) {
@@ -230,7 +230,7 @@ protected function download_language_pack( $download, $slug = null ) {
230230
}
231231

232232
$upgrader = 'WP_CLI\\LanguagePackUpgrader';
233-
$result = Utils\get_upgrader( $upgrader )->upgrade( $translation, array( 'clear_update_cache' => false ) );
233+
$result = Utils\get_upgrader( $upgrader )->upgrade( $translation, array( 'clear_update_cache' => false ) );
234234

235235
if ( is_wp_error( $result ) ) {
236236
return $result;
@@ -251,8 +251,8 @@ protected function download_language_pack( $download, $slug = null ) {
251251
* @return array
252252
*/
253253
protected function get_installed_languages( $slug = 'default' ) {
254-
$available = wp_get_installed_translations( $this->obj_type );
255-
$available = ! empty( $available[ $slug ] ) ? array_keys( $available[ $slug ] ) : array();
254+
$available = wp_get_installed_translations( $this->obj_type );
255+
$available = ! empty( $available[ $slug ] ) ? array_keys( $available[ $slug ] ) : array();
256256
$available[] = 'en_US';
257257

258258
return $available;
@@ -295,10 +295,10 @@ protected function get_all_languages( $slug = null ) {
295295
$translations = ! empty( $response['translations'] ) ? $response['translations'] : array();
296296

297297
$en_us = array(
298-
'language' => 'en_US',
298+
'language' => 'en_US',
299299
'english_name' => 'English (United States)',
300-
'native_name' => 'English (United States)',
301-
'updated' => '',
300+
'native_name' => 'English (United States)',
301+
'updated' => '',
302302
);
303303

304304
$translations[] = $en_us;

src/WP_CLI/LanguagePackUpgrader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ public function download_package( $package ) {
8282

8383
$temp = \WP_CLI\Utils\get_temp_dir() . uniqid( 'wp_' ) . '.' . $ext;
8484

85-
$cache = WP_CLI::get_cache();
86-
$cache_key = "translation/{$type}-{$slug}-{$version}-{$language}-{$updated}.{$ext}";
85+
$cache = WP_CLI::get_cache();
86+
$cache_key = "translation/{$type}-{$slug}-{$version}-{$language}-{$updated}.{$ext}";
8787
$cache_file = $cache->has( $cache_key );
8888

8989
if ( $cache_file ) {

0 commit comments

Comments
 (0)