Skip to content

Commit bd3f6d6

Browse files
Update to WPCS v3 (#176)
* Update to WPCS v3 * Remove legacy PHPCS sniff * Revert "Remove legacy PHPCS sniff" This reverts commit eb88d7b. * Update some sniff references * Auto-fix some violations * Ignore another sniff * Update a few more sniffs * Fix one more sniff
1 parent 1d25e64 commit bd3f6d6

File tree

6 files changed

+17
-14
lines changed

6 files changed

+17
-14
lines changed

WP_CLI_CS/ruleset.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,17 @@
7373
<exclude name="Generic.PHP.BacktickOperator"/>
7474

7575
<!-- We want to stick with short array syntax for WP-CLI. -->
76-
<exclude name="Generic.Arrays.DisallowShortArraySyntax"/>
76+
<exclude name="Universal.Arrays.DisallowShortArraySyntax.Found"/>
7777

7878
<!-- Keep short ternaries around for WP-CLI. -->
79-
<exclude name="WordPress.PHP.DisallowShortTernary"/>
79+
<exclude name="Universal.Operators.DisallowShortTernary.Found"/>
80+
81+
<!-- Allow filesystem operations because WordPress APIs may not be available -->
82+
<exclude name="WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents" />
83+
<exclude name="WordPress.WP.AlternativeFunctions.file_system_operations_mkdir" />
84+
<exclude name="WordPress.WP.AlternativeFunctions.file_system_operations_rmdir" />
85+
<exclude name="WordPress.WP.AlternativeFunctions.rename_rename" />
86+
<exclude name="WordPress.WP.AlternativeFunctions.unlink_unlink" />
8087

8188
</rule>
8289

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"wp-cli/core-command": "^1 || ^2",
2020
"wp-cli/eval-command": "^1 || ^2",
2121
"wp-cli/wp-cli": "^2.5.1",
22-
"wp-coding-standards/wpcs": "^2.3.0",
22+
"wp-coding-standards/wpcs": "^3",
2323
"yoast/phpunit-polyfills": "^1.0.3"
2424
},
2525
"require-dev": {

src/Context/FeatureContext.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,7 @@ private static function log_run_times_after_scenario( $scope ) {
10611061
$scenario_key = self::get_scenario_key( $scope );
10621062
if ( $scenario_key ) {
10631063
self::$scenario_run_times[ $scenario_key ] += microtime( true );
1064-
self::$scenario_count++;
1064+
++self::$scenario_count;
10651065
if ( count( self::$scenario_run_times ) > self::$num_top_scenarios ) {
10661066
arsort( self::$scenario_run_times );
10671067
array_pop( self::$scenario_run_times );
@@ -1094,11 +1094,9 @@ private static function dir_diff_copy( $upd_dir, $src_dir, $cop_dir ) {
10941094
throw new RuntimeException( sprintf( "Failed to create copy directory '%s': %s. " . __FILE__ . ':' . __LINE__, $cop_file, $error['message'] ) );
10951095
}
10961096
self::copy_dir( $upd_file, $cop_file );
1097-
} else {
1098-
if ( ! copy( $upd_file, $cop_file ) ) {
1097+
} elseif ( ! copy( $upd_file, $cop_file ) ) {
10991098
$error = error_get_last();
11001099
throw new RuntimeException( sprintf( "Failed to copy '%s' to '%s': %s. " . __FILE__ . ':' . __LINE__, $upd_file, $cop_file, $error['message'] ) );
1101-
}
11021100
}
11031101
} elseif ( is_dir( $upd_file ) ) {
11041102
self::dir_diff_copy( $upd_file, $src_file, $cop_file );
@@ -1229,10 +1227,11 @@ private static function log_proc_method_run_time( $key, $start_time ) {
12291227
self::$proc_method_run_times[ $key ] = [ 0, 0 ];
12301228
}
12311229
self::$proc_method_run_times[ $key ][0] += $run_time;
1232-
self::$proc_method_run_times[ $key ][1]++;
1230+
++self::$proc_method_run_times[ $key ][1];
12331231
}
12341232
}
12351233

1234+
// phpcs:ignore Universal.Files.SeparateFunctionsFromOO.Mixed
12361235
function wp_cli_behat_env_debug( $message ) {
12371236
if ( ! getenv( 'WP_CLI_TEST_DEBUG_BEHAT_ENV' ) ) {
12381237
return;
@@ -1301,7 +1300,6 @@ function wpcli_bootstrap_behat_feature_context() {
13011300

13021301
wp_cli_behat_env_debug( "Project config file location: {$project_config}" );
13031302
wp_cli_behat_env_debug( "Project config:\n{$contents}" );
1304-
13051303
}
13061304

13071305
wpcli_bootstrap_behat_feature_context();

src/Context/Support.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ protected function assert_not_regex( $regex, $actual ) {
2525
}
2626

2727
protected function assert_equals( $expected, $actual ) {
28-
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- Deliberate loose comparison.
28+
// phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual -- Deliberate loose comparison.
2929
if ( $expected != $actual ) {
3030
throw new Exception( 'Actual value: ' . var_export( $actual, true ) );
3131
}
3232
}
3333

3434
protected function assert_not_equals( $expected, $actual ) {
35-
// phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison -- Deliberate loose comparison.
35+
// phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual -- Deliberate loose comparison.
3636
if ( $expected == $actual ) {
3737
throw new Exception( 'Actual value: ' . var_export( $actual, true ) );
3838
}
@@ -200,7 +200,7 @@ protected function check_that_csv_string_contains_values( $actual_csv, $expected
200200
);
201201

202202
if ( $actual_row === $expected_row ) {
203-
$expected_result++;
203+
++$expected_result;
204204
}
205205
}
206206
}

src/Context/WhenStepDefinitions.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,3 @@ public function when_i_run_the_previous_command_again( $mode ) {
6262
list( $this->result->stdout, $this->email_sends ) = $this->wpcli_tests_capture_email_sends( $this->result->stdout );
6363
}
6464
}
65-

tests/bootstrap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,3 @@ function wpcli_tests_include_config( array $config_filenames = [] ) {
5959
'.phpunit.xml.dist',
6060
]
6161
);
62-

0 commit comments

Comments
 (0)