Skip to content

Commit

Permalink
changes to show errors less severity
Browse files Browse the repository at this point in the history
  • Loading branch information
davidperezgar committed Oct 10, 2024
1 parent fb7717e commit 398ab67
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions includes/CLI/Plugin_Check_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public function __construct( Plugin_Context $plugin_context ) {
* [--warning-severity=<warning-severity>]
* : Warning severity level.
*
* [--include-error-severity]
* : Include less level of severity issues as warning.
*
* [--slug=<slug>]
* : Slug to override the default.
*
Expand Down Expand Up @@ -140,15 +143,16 @@ public function check( $args, $assoc_args ) {
$options = $this->get_options(
$assoc_args,
array(
'checks' => '',
'format' => 'table',
'ignore-warnings' => false,
'ignore-errors' => false,
'include-experimental' => false,
'severity' => '',
'error-severity' => '',
'warning-severity' => '',
'slug' => '',
'checks' => '',
'format' => 'table',
'ignore-warnings' => false,
'ignore-errors' => false,
'include-experimental' => false,
'severity' => '',
'error-severity' => '',
'warning-severity' => '',
'include-error-severity' => '',
'slug' => '',

Check warning on line 155 in includes/CLI/Plugin_Check_Command.php

View check run for this annotation

Codecov / codecov/patch

includes/CLI/Plugin_Check_Command.php#L146-L155

Added lines #L146 - L155 were not covered by tests
)
);

Expand Down Expand Up @@ -256,8 +260,9 @@ static function ( $dirs ) use ( $excluded_files ) {
$formatter = $this->get_formatter( $assoc_args, $default_fields );

// Severity.
$error_severity = ! empty( $options['error-severity'] ) ? $options['error-severity'] : $options['severity'];
$warning_severity = ! empty( $options['warning-severity'] ) ? $options['warning-severity'] : $options['severity'];
$error_severity = ! empty( $options['error-severity'] ) ? $options['error-severity'] : $options['severity'];
$warning_severity = ! empty( $options['warning-severity'] ) ? $options['warning-severity'] : $options['severity'];
$show_error_severity = ! empty( $options['include-error-severity'] ) ? true : false;

Check warning on line 265 in includes/CLI/Plugin_Check_Command.php

View check run for this annotation

Codecov / codecov/patch

includes/CLI/Plugin_Check_Command.php#L263-L265

Added lines #L263 - L265 were not covered by tests

// Print the formatted results.
// Go over all files with errors first and print them, combined with any warnings in the same file.
Expand All @@ -270,7 +275,7 @@ static function ( $dirs ) use ( $excluded_files ) {
$file_results = $this->flatten_file_results( $file_errors, $file_warnings );

if ( '' !== $error_severity || '' !== $warning_severity ) {
$file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ) );
$file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ), $show_error_severity );

Check warning on line 278 in includes/CLI/Plugin_Check_Command.php

View check run for this annotation

Codecov / codecov/patch

includes/CLI/Plugin_Check_Command.php#L278

Added line #L278 was not covered by tests
}

if ( ! empty( $file_results ) ) {
Expand Down Expand Up @@ -670,7 +675,7 @@ private function has_runtime_check( array $checks ) {
* @param int $warning_severity Warning severity level.
* @return array Filtered results.
*/
private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity ) {
private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity, $show_error_severity = false ) {

Check warning on line 678 in includes/CLI/Plugin_Check_Command.php

View check run for this annotation

Codecov / codecov/patch

includes/CLI/Plugin_Check_Command.php#L678

Added line #L678 was not covered by tests
$errors = array_filter(
$results,
function ( $item ) use ( $error_severity ) {
Expand All @@ -679,20 +684,23 @@ function ( $item ) use ( $error_severity ) {
);

// Converts errors to warnings if severity is less than the error severity level.
$errors_warning = array_filter(
$results,
function ( $item ) use ( $error_severity ) {
return ( 'ERROR' === $item['type'] && $item['severity'] < $error_severity );
}
);

$errors_warning = array_map(
function ( $item ) {
$item['type'] = 'WARNING';
return $item;
},
$errors_warning
);
$errors_warning = array();
if ( $show_error_severity ) {
$errors_warning = array_filter(
$results,
function ( $item ) use ( $error_severity ) {
return ( 'ERROR' === $item['type'] && $item['severity'] < $error_severity );

Check warning on line 692 in includes/CLI/Plugin_Check_Command.php

View check run for this annotation

Codecov / codecov/patch

includes/CLI/Plugin_Check_Command.php#L687-L692

Added lines #L687 - L692 were not covered by tests
}
);

$errors_warning = array_map(
function ( $item ) {
$item['type'] = 'WARNING';
return $item;
},
$errors_warning

Check warning on line 701 in includes/CLI/Plugin_Check_Command.php

View check run for this annotation

Codecov / codecov/patch

includes/CLI/Plugin_Check_Command.php#L696-L701

Added lines #L696 - L701 were not covered by tests
);
}

$warnings = array_filter(
$results,
Expand Down

0 comments on commit 398ab67

Please sign in to comment.