Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to WPCS v3 #176

Merged
merged 8 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions WP_CLI_CS/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,17 @@
<exclude name="Generic.PHP.BacktickOperator"/>

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

<!-- Keep short ternaries around for WP-CLI. -->
<exclude name="WordPress.PHP.DisallowShortTernary"/>
<exclude name="Universal.Operators.DisallowShortTernary.Found"/>

<!-- Allow filesystem operations because WordPress APIs may not be available -->
<exclude name="WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents" />
<exclude name="WordPress.WP.AlternativeFunctions.file_system_operations_mkdir" />
<exclude name="WordPress.WP.AlternativeFunctions.file_system_operations_rmdir" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also add is_writable()

<exclude name="WordPress.WP.AlternativeFunctions.rename_rename" />
<exclude name="WordPress.WP.AlternativeFunctions.unlink_unlink" />

</rule>

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"wp-cli/core-command": "^1 || ^2",
"wp-cli/eval-command": "^1 || ^2",
"wp-cli/wp-cli": "^2.5.1",
"wp-coding-standards/wpcs": "^2.3.0",
"wp-coding-standards/wpcs": "^3",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommended: remove the explicit dealerdirect/phpcodesniffer-composer-installer require. That now comes with WPCS and removing it will prevent potential future version conflicts.

"yoast/phpunit-polyfills": "^1.0.3"
},
"require-dev": {
Expand Down
10 changes: 4 additions & 6 deletions src/Context/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ private static function log_run_times_after_scenario( $scope ) {
$scenario_key = self::get_scenario_key( $scope );
if ( $scenario_key ) {
self::$scenario_run_times[ $scenario_key ] += microtime( true );
self::$scenario_count++;
++self::$scenario_count;
if ( count( self::$scenario_run_times ) > self::$num_top_scenarios ) {
arsort( self::$scenario_run_times );
array_pop( self::$scenario_run_times );
Expand Down Expand Up @@ -1094,11 +1094,9 @@ private static function dir_diff_copy( $upd_dir, $src_dir, $cop_dir ) {
throw new RuntimeException( sprintf( "Failed to create copy directory '%s': %s. " . __FILE__ . ':' . __LINE__, $cop_file, $error['message'] ) );
}
self::copy_dir( $upd_file, $cop_file );
} else {
if ( ! copy( $upd_file, $cop_file ) ) {
} elseif ( ! copy( $upd_file, $cop_file ) ) {
$error = error_get_last();
throw new RuntimeException( sprintf( "Failed to copy '%s' to '%s': %s. " . __FILE__ . ':' . __LINE__, $upd_file, $cop_file, $error['message'] ) );
Comment on lines 1098 to 1099
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the indent here didn't get fixed ?

}
}
} elseif ( is_dir( $upd_file ) ) {
self::dir_diff_copy( $upd_file, $src_file, $cop_file );
Expand Down Expand Up @@ -1229,10 +1227,11 @@ private static function log_proc_method_run_time( $key, $start_time ) {
self::$proc_method_run_times[ $key ] = [ 0, 0 ];
}
self::$proc_method_run_times[ $key ][0] += $run_time;
self::$proc_method_run_times[ $key ][1]++;
++self::$proc_method_run_times[ $key ][1];
}
}

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

wp_cli_behat_env_debug( "Project config file location: {$project_config}" );
wp_cli_behat_env_debug( "Project config:\n{$contents}" );

}

wpcli_bootstrap_behat_feature_context();
6 changes: 3 additions & 3 deletions src/Context/Support.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ protected function assert_not_regex( $regex, $actual ) {
}

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

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

if ( $actual_row === $expected_row ) {
$expected_result++;
++$expected_result;
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Context/WhenStepDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,3 @@ public function when_i_run_the_previous_command_again( $mode ) {
list( $this->result->stdout, $this->email_sends ) = $this->wpcli_tests_capture_email_sends( $this->result->stdout );
}
}

1 change: 0 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,3 @@ function wpcli_tests_include_config( array $config_filenames = [] ) {
'.phpunit.xml.dist',
]
);