From 0c49f42c705791e71519cc7028a2e3746703ba85 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Thu, 3 Oct 2024 22:42:57 +0200 Subject: [PATCH 01/23] convert errors less severity to warnings --- includes/CLI/Plugin_Check_Command.php | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index 05f93faad..f01feb89a 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -678,6 +678,22 @@ 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 + ); + $warnings = array_filter( $results, function ( $item ) use ( $warning_severity ) { @@ -685,6 +701,6 @@ function ( $item ) use ( $warning_severity ) { } ); - return array_merge( $errors, $warnings ); + return array_merge( $errors, $errors_warning, $warnings ); } } From 42ad9f60aa5d45e6b05395e740a3c5bf6303db04 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Thu, 3 Oct 2024 22:57:10 +0200 Subject: [PATCH 02/23] updated behat tests --- .../features/plugin-check-severity.feature | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/tests/behat/features/plugin-check-severity.feature b/tests/behat/features/plugin-check-severity.feature index 38323ae62..1e3f6113d 100644 --- a/tests/behat/features/plugin-check-severity.feature +++ b/tests/behat/features/plugin-check-severity.feature @@ -125,7 +125,7 @@ Feature: Test that the severity level in plugin check works. """ And STDOUT should not contain: """ - WordPress.WP.AlternativeFunctions.rand_mt_rand,ERROR,5 + WordPress.WP.AlternativeFunctions.rand_mt_rand,WARNING,5 """ And STDOUT should contain: """ @@ -151,7 +151,7 @@ Feature: Test that the severity level in plugin check works. """ And STDOUT should not contain: """ - WordPress.WP.AlternativeFunctions.rand_mt_rand,ERROR,5 + WordPress.WP.AlternativeFunctions.rand_mt_rand,WARNING,5 """ And STDOUT should contain: """ @@ -193,4 +193,27 @@ Feature: Test that the severity level in plugin check works. """ When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity --severity=10` - Then STDOUT should be empty + Then STDOUT should contain: + """ + allow_unfiltered_uploads_detected,WARNING,7 + """ + And STDOUT should contain: + """ + obfuscated_code_detected,WARNING,6 + """ + And STDOUT should contain: + """ + WordPress.WP.AlternativeFunctions.rand_mt_rand,WARNING,5 + """ + And STDOUT should contain: + """ + outdated_tested_upto_header,WARNING,7 + """ + And STDOUT should contain: + """ + default_readme_text,WARNING,7 + """ + And STDOUT should not contain: + """ + upgrade_notice_limit,WARNING,5 + """ From 56c77f7f2e8072c73abcdd1ed45b65edbc88db21 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Thu, 3 Oct 2024 23:04:12 +0200 Subject: [PATCH 03/23] updated tests --- tests/behat/features/plugin-check-severity.feature | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/behat/features/plugin-check-severity.feature b/tests/behat/features/plugin-check-severity.feature index 1e3f6113d..8a917fe5d 100644 --- a/tests/behat/features/plugin-check-severity.feature +++ b/tests/behat/features/plugin-check-severity.feature @@ -123,7 +123,7 @@ Feature: Test that the severity level in plugin check works. """ obfuscated_code_detected,ERROR,6 """ - And STDOUT should not contain: + And STDOUT should contain: """ WordPress.WP.AlternativeFunctions.rand_mt_rand,WARNING,5 """ @@ -149,7 +149,7 @@ Feature: Test that the severity level in plugin check works. """ obfuscated_code_detected,ERROR,6 """ - And STDOUT should not contain: + And STDOUT should contain: """ WordPress.WP.AlternativeFunctions.rand_mt_rand,WARNING,5 """ @@ -209,7 +209,7 @@ Feature: Test that the severity level in plugin check works. """ outdated_tested_upto_header,WARNING,7 """ - And STDOUT should contain: + And STDOUT should not contain: """ default_readme_text,WARNING,7 """ From 398ab67ed51e56db6fe14cb8ac80ad0ce561afbb Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Thu, 10 Oct 2024 22:50:16 +0200 Subject: [PATCH 04/23] changes to show errors less severity --- includes/CLI/Plugin_Check_Command.php | 62 +++++++++++++++------------ 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index f01feb89a..98baaf7fd 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -113,6 +113,9 @@ public function __construct( Plugin_Context $plugin_context ) { * [--warning-severity=] * : Warning severity level. * + * [--include-error-severity] + * : Include less level of severity issues as warning. + * * [--slug=] * : Slug to override the default. * @@ -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' => '', ) ); @@ -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; // Print the formatted results. // Go over all files with errors first and print them, combined with any warnings in the same file. @@ -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 ); } if ( ! empty( $file_results ) ) { @@ -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 ) { $errors = array_filter( $results, function ( $item ) use ( $error_severity ) { @@ -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 ); + } + ); + + $errors_warning = array_map( + function ( $item ) { + $item['type'] = 'WARNING'; + return $item; + }, + $errors_warning + ); + } $warnings = array_filter( $results, From 9fed972cf968c401686640d7f0af6e436a8507f0 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Thu, 10 Oct 2024 22:56:50 +0200 Subject: [PATCH 05/23] phptests fixes --- includes/CLI/Plugin_Check_Command.php | 3 +- .../features/plugin-check-severity.feature | 33 +++---------------- 2 files changed, 7 insertions(+), 29 deletions(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index 98baaf7fd..4639be4b6 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -673,6 +673,7 @@ private function has_runtime_check( array $checks ) { * @param array $results Check results. * @param int $error_severity Error severity level. * @param int $warning_severity Warning severity level. + * @param bool $show_error_severity Show error severity as warning. * @return array Filtered results. */ private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity, $show_error_severity = false ) { @@ -692,7 +693,7 @@ function ( $item ) use ( $error_severity ) { return ( 'ERROR' === $item['type'] && $item['severity'] < $error_severity ); } ); - + $errors_warning = array_map( function ( $item ) { $item['type'] = 'WARNING'; diff --git a/tests/behat/features/plugin-check-severity.feature b/tests/behat/features/plugin-check-severity.feature index 8a917fe5d..46b0efde2 100644 --- a/tests/behat/features/plugin-check-severity.feature +++ b/tests/behat/features/plugin-check-severity.feature @@ -123,9 +123,9 @@ Feature: Test that the severity level in plugin check works. """ obfuscated_code_detected,ERROR,6 """ - And STDOUT should contain: + And STDOUT should not contain: """ - WordPress.WP.AlternativeFunctions.rand_mt_rand,WARNING,5 + WordPress.WP.AlternativeFunctions.rand_mt_rand,ERROR,5 """ And STDOUT should contain: """ @@ -149,9 +149,9 @@ Feature: Test that the severity level in plugin check works. """ obfuscated_code_detected,ERROR,6 """ - And STDOUT should contain: + And STDOUT should not contain: """ - WordPress.WP.AlternativeFunctions.rand_mt_rand,WARNING,5 + WordPress.WP.AlternativeFunctions.rand_mt_rand,ERROR,5 """ And STDOUT should contain: """ @@ -193,27 +193,4 @@ Feature: Test that the severity level in plugin check works. """ When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity --severity=10` - Then STDOUT should contain: - """ - allow_unfiltered_uploads_detected,WARNING,7 - """ - And STDOUT should contain: - """ - obfuscated_code_detected,WARNING,6 - """ - And STDOUT should contain: - """ - WordPress.WP.AlternativeFunctions.rand_mt_rand,WARNING,5 - """ - And STDOUT should contain: - """ - outdated_tested_upto_header,WARNING,7 - """ - And STDOUT should not contain: - """ - default_readme_text,WARNING,7 - """ - And STDOUT should not contain: - """ - upgrade_notice_limit,WARNING,5 - """ + Then STDOUT should be empty \ No newline at end of file From 2526c947bf57fec3fb4d154cf083d35f4123f111 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Fri, 11 Oct 2024 19:04:15 +0200 Subject: [PATCH 06/23] added behat testing --- tests/behat/features/plugin-check-severity.feature | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/behat/features/plugin-check-severity.feature b/tests/behat/features/plugin-check-severity.feature index 46b0efde2..0343141b9 100644 --- a/tests/behat/features/plugin-check-severity.feature +++ b/tests/behat/features/plugin-check-severity.feature @@ -192,5 +192,19 @@ Feature: Test that the severity level in plugin check works. upgrade_notice_limit,WARNING,5 """ + When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity --error-severity=7 --include-error-severity` + Then STDOUT should contain: + """ + allow_unfiltered_uploads_detected,ERROR,7 + """ + And STDOUT should contain: + """ + default_readme_text,WARNING,7 + """ + And STDOUT should contain: + """ + upgrade_notice_limit,WARNING,5 + """ + When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity --severity=10` Then STDOUT should be empty \ No newline at end of file From 5437ba4eb30e14fb99b734cbcfee15739733d537 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Fri, 11 Oct 2024 19:11:59 +0200 Subject: [PATCH 07/23] phpmd test fixed --- includes/CLI/Plugin_Check_Command.php | 81 +++++++++++++++++---------- 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index 4639be4b6..d5b7eb69f 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -275,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 ), $show_error_severity ); + $file_results = $this->get_filtered_results( $file_results, intval( $error_severity ), intval( $warning_severity ), $show_error_severity ); } if ( ! empty( $file_results ) ) { @@ -288,7 +288,7 @@ static function ( $dirs ) use ( $excluded_files ) { $file_results = $this->flatten_file_results( array(), $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( $file_results, intval( $error_severity ), intval( $warning_severity ) ); } if ( ! empty( $file_results ) ) { @@ -666,9 +666,7 @@ private function has_runtime_check( array $checks ) { } /** - * Returns check results filtered by severity level. - * - * @since 1.1.0 + * Returns check results filtered by severity level, with optional error-to-warning conversion. * * @param array $results Check results. * @param int $error_severity Error severity level. @@ -676,40 +674,65 @@ private function has_runtime_check( array $checks ) { * @param bool $show_error_severity Show error severity as warning. * @return array Filtered results. */ - private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity, $show_error_severity = false ) { + private function get_filtered_results( $results, $error_severity, $warning_severity, $show_error_severity = false ) { + // First, get the filtered errors and warnings. + $filtered_results = $this->get_filtered_results_by_severity( $results, $error_severity, $warning_severity ); + + // If requested, convert certain errors to warnings. + if ( $show_error_severity ) { + $errors_as_warnings = $this->convert_errors_to_warnings( $results, $error_severity ); + return array_merge( $filtered_results, $errors_as_warnings ); + } + + return $filtered_results; + } + /** + * Returns check results filtered by severity level. + * + * @param array $results Check results. + * @param int $error_severity Error severity level. + * @param int $warning_severity Warning severity level. + * @return array Filtered results. + */ + private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity ) { $errors = array_filter( - $results, - function ( $item ) use ( $error_severity ) { - return ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity ); - } + $results, + function ( $item ) use ( $error_severity ) { + return ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity ); + } ); - // Converts errors to warnings if severity is less than the error severity level. - $errors_warning = array(); - if ( $show_error_severity ) { - $errors_warning = array_filter( + $warnings = array_filter( + $results, + function ( $item ) use ( $warning_severity ) { + return ( 'WARNING' === $item['type'] && $item['severity'] >= $warning_severity ); + } + ); + + return array_merge( $errors, $warnings ); + } + /** + * Converts errors below the severity threshold to warnings. + * + * @param array $results Check results. + * @param int $error_severity Error severity level threshold. + * @return array Converted results where applicable. + */ + private function convert_errors_to_warnings( $results, $error_severity ) { + $errors_warning = array_filter( $results, function ( $item ) use ( $error_severity ) { - return ( 'ERROR' === $item['type'] && $item['severity'] < $error_severity ); + return ( 'ERROR' === $item['type'] && $item['severity'] < $error_severity ); } - ); + ); - $errors_warning = array_map( + return array_map( function ( $item ) { - $item['type'] = 'WARNING'; - return $item; + $item['type'] = 'WARNING'; + return $item; }, $errors_warning - ); - } - - $warnings = array_filter( - $results, - function ( $item ) use ( $warning_severity ) { - return ( 'WARNING' === $item['type'] && $item['severity'] >= $warning_severity ); - } ); - - return array_merge( $errors, $errors_warning, $warnings ); } + } From a76a7e53729257c714840e0a54196d0dd25d8c06 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Fri, 11 Oct 2024 19:18:42 +0200 Subject: [PATCH 08/23] fix phplint --- includes/CLI/Plugin_Check_Command.php | 35 +++++++++++++-------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index d5b7eb69f..b40f8e150 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -696,17 +696,17 @@ private function get_filtered_results( $results, $error_severity, $warning_sever */ private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity ) { $errors = array_filter( - $results, - function ( $item ) use ( $error_severity ) { - return ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity ); - } + $results, + function ( $item ) use ( $error_severity ) { + return ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity ); + } ); $warnings = array_filter( - $results, - function ( $item ) use ( $warning_severity ) { - return ( 'WARNING' === $item['type'] && $item['severity'] >= $warning_severity ); - } + $results, + function ( $item ) use ( $warning_severity ) { + return ( 'WARNING' === $item['type'] && $item['severity'] >= $warning_severity ); + } ); return array_merge( $errors, $warnings ); @@ -720,19 +720,18 @@ function ( $item ) use ( $warning_severity ) { */ private function convert_errors_to_warnings( $results, $error_severity ) { $errors_warning = array_filter( - $results, - function ( $item ) use ( $error_severity ) { - return ( 'ERROR' === $item['type'] && $item['severity'] < $error_severity ); - } + $results, + function ( $item ) use ( $error_severity ) { + return ( 'ERROR' === $item['type'] && $item['severity'] < $error_severity ); + } ); return array_map( - function ( $item ) { - $item['type'] = 'WARNING'; - return $item; - }, - $errors_warning + function ( $item ) { + $item['type'] = 'WARNING'; + return $item; + }, + $errors_warning ); } - } From 3984d64e17e37faae028b836a59db29b85b4c9a4 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Sat, 12 Oct 2024 13:12:06 +0200 Subject: [PATCH 09/23] fix phpmd test --- includes/CLI/Plugin_Check_Command.php | 61 ++++++++++++--------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index b40f8e150..ca2087877 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -275,7 +275,11 @@ 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( $file_results, intval( $error_severity ), intval( $warning_severity ), $show_error_severity ); + $file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ) ); + if ( $show_error_severity ) { + $file_warning_results = $this->convert_filtered_errors_by_severity( $file_results, intval( $error_severity ) ); + $file_results = array_merge( $file_results, $file_warning_results ); + } } if ( ! empty( $file_results ) ) { @@ -288,7 +292,7 @@ static function ( $dirs ) use ( $excluded_files ) { $file_results = $this->flatten_file_results( array(), $file_warnings ); if ( '' !== $error_severity || '' !== $warning_severity ) { - $file_results = $this->get_filtered_results( $file_results, intval( $error_severity ), intval( $warning_severity ) ); + $file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ) ); } if ( ! empty( $file_results ) ) { @@ -665,30 +669,11 @@ private function has_runtime_check( array $checks ) { return false; } - /** - * Returns check results filtered by severity level, with optional error-to-warning conversion. - * - * @param array $results Check results. - * @param int $error_severity Error severity level. - * @param int $warning_severity Warning severity level. - * @param bool $show_error_severity Show error severity as warning. - * @return array Filtered results. - */ - private function get_filtered_results( $results, $error_severity, $warning_severity, $show_error_severity = false ) { - // First, get the filtered errors and warnings. - $filtered_results = $this->get_filtered_results_by_severity( $results, $error_severity, $warning_severity ); - - // If requested, convert certain errors to warnings. - if ( $show_error_severity ) { - $errors_as_warnings = $this->convert_errors_to_warnings( $results, $error_severity ); - return array_merge( $filtered_results, $errors_as_warnings ); - } - - return $filtered_results; - } /** * Returns check results filtered by severity level. * + * @since 1.1.0 + * * @param array $results Check results. * @param int $error_severity Error severity level. * @param int $warning_severity Warning severity level. @@ -698,40 +683,46 @@ private function get_filtered_results_by_severity( $results, $error_severity, $w $errors = array_filter( $results, function ( $item ) use ( $error_severity ) { - return ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity ); + return ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity ); } ); $warnings = array_filter( $results, function ( $item ) use ( $warning_severity ) { - return ( 'WARNING' === $item['type'] && $item['severity'] >= $warning_severity ); + return ( 'WARNING' === $item['type'] && $item['severity'] >= $warning_severity ); } ); return array_merge( $errors, $warnings ); } + /** - * Converts errors below the severity threshold to warnings. + * Returns check results filtered by severity level. + * + * @since 1.1.0 * - * @param array $results Check results. - * @param int $error_severity Error severity level threshold. - * @return array Converted results where applicable. + * @param array $results Check results. + * @param int $error_severity Error severity level. + * @param int $warning_severity Warning severity level. + * @return array Filtered results. */ - private function convert_errors_to_warnings( $results, $error_severity ) { + private function convert_filtered_errors_by_severity( $results, $error_severity ) { $errors_warning = array_filter( $results, function ( $item ) use ( $error_severity ) { - return ( 'ERROR' === $item['type'] && $item['severity'] < $error_severity ); + return ( 'ERROR' === $item['type'] && $item['severity'] < $error_severity ); } ); - return array_map( + $errors_warning = array_map( function ( $item ) { - $item['type'] = 'WARNING'; - return $item; + $item['type'] = 'WARNING'; + return $item; }, $errors_warning ); + + return $errors_warning; } -} +} \ No newline at end of file From 9342ddaec59425cc3fcd279978cc42b78041b14b Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Sat, 12 Oct 2024 13:14:41 +0200 Subject: [PATCH 10/23] fix phplint --- includes/CLI/Plugin_Check_Command.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index ca2087877..99f38c95b 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -704,7 +704,6 @@ function ( $item ) use ( $warning_severity ) { * * @param array $results Check results. * @param int $error_severity Error severity level. - * @param int $warning_severity Warning severity level. * @return array Filtered results. */ private function convert_filtered_errors_by_severity( $results, $error_severity ) { @@ -725,4 +724,4 @@ function ( $item ) { return $errors_warning; } -} \ No newline at end of file +} From 9886683ae40ef8b4ff34edf68f1b86d4bb750b67 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Wed, 16 Oct 2024 21:15:32 +0200 Subject: [PATCH 11/23] changed as commented --- includes/CLI/Plugin_Check_Command.php | 79 ++++++------------- .../features/plugin-check-severity.feature | 4 +- 2 files changed, 28 insertions(+), 55 deletions(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index 99f38c95b..e9cf63ff9 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -113,7 +113,7 @@ public function __construct( Plugin_Context $plugin_context ) { * [--warning-severity=] * : Warning severity level. * - * [--include-error-severity] + * [--include-low-severity-errors] * : Include less level of severity issues as warning. * * [--slug=] @@ -143,16 +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' => '', - 'include-error-severity' => '', - 'slug' => '', + 'checks' => '', + 'format' => 'table', + 'ignore-warnings' => false, + 'ignore-errors' => false, + 'include-experimental' => false, + 'severity' => '', + 'error-severity' => '', + 'warning-severity' => '', + 'include-low-severity-errors' => '', + 'slug' => '', ) ); @@ -260,9 +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']; - $show_error_severity = ! empty( $options['include-error-severity'] ) ? true : false; + $error_severity = ! empty( $options['error-severity'] ) ? $options['error-severity'] : $options['severity']; + $warning_severity = ! empty( $options['warning-severity'] ) ? $options['warning-severity'] : $options['severity']; + $include_low_severity_errors = ! empty( $options['include-low-severity-errors'] ) ? true : false; // Print the formatted results. // Go over all files with errors first and print them, combined with any warnings in the same file. @@ -275,11 +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 ) ); - if ( $show_error_severity ) { - $file_warning_results = $this->convert_filtered_errors_by_severity( $file_results, intval( $error_severity ) ); - $file_results = array_merge( $file_results, $file_warning_results ); - } + $file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ), $include_low_severity_errors ); } if ( ! empty( $file_results ) ) { @@ -677,15 +673,20 @@ private function has_runtime_check( array $checks ) { * @param array $results Check results. * @param int $error_severity Error severity level. * @param int $warning_severity Warning severity level. + * @param bool $include_low_severity_errors Include less level of severity issues as warning. * @return array Filtered results. */ - private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity ) { - $errors = array_filter( - $results, - function ( $item ) use ( $error_severity ) { - return ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity ); + private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity, $include_low_severity_errors = false ) { + $errors = array(); + foreach ( $results as $item ) { + if ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity ) { + $errors[] = $item; + } elseif ( $include_low_severity_errors && $item['severity'] < $error_severity ) { + $item['type'] = 'WARNING'; + $item['severity'] = 10; + $errors[] = $item; } - ); + } $warnings = array_filter( $results, @@ -696,32 +697,4 @@ function ( $item ) use ( $warning_severity ) { return array_merge( $errors, $warnings ); } - - /** - * Returns check results filtered by severity level. - * - * @since 1.1.0 - * - * @param array $results Check results. - * @param int $error_severity Error severity level. - * @return array Filtered results. - */ - private function convert_filtered_errors_by_severity( $results, $error_severity ) { - $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 - ); - - return $errors_warning; - } } diff --git a/tests/behat/features/plugin-check-severity.feature b/tests/behat/features/plugin-check-severity.feature index 0343141b9..91017f91d 100644 --- a/tests/behat/features/plugin-check-severity.feature +++ b/tests/behat/features/plugin-check-severity.feature @@ -192,7 +192,7 @@ Feature: Test that the severity level in plugin check works. upgrade_notice_limit,WARNING,5 """ - When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity --error-severity=7 --include-error-severity` + When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity --error-severity=7 --include-low-severity-errors` Then STDOUT should contain: """ allow_unfiltered_uploads_detected,ERROR,7 @@ -203,7 +203,7 @@ Feature: Test that the severity level in plugin check works. """ And STDOUT should contain: """ - upgrade_notice_limit,WARNING,5 + upgrade_notice_limit,WARNING,10 """ When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity --severity=10` From 68834e49496ed071b2741f16c1b74051c51f2915 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Wed, 16 Oct 2024 21:17:09 +0200 Subject: [PATCH 12/23] new line --- tests/behat/features/plugin-check-severity.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/behat/features/plugin-check-severity.feature b/tests/behat/features/plugin-check-severity.feature index 91017f91d..0f6494881 100644 --- a/tests/behat/features/plugin-check-severity.feature +++ b/tests/behat/features/plugin-check-severity.feature @@ -207,4 +207,4 @@ Feature: Test that the severity level in plugin check works. """ When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity --severity=10` - Then STDOUT should be empty \ No newline at end of file + Then STDOUT should be empty From e4275c1dba6257f4fa3d0aa35fa012747552bb79 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Wed, 16 Oct 2024 22:45:05 +0200 Subject: [PATCH 13/23] remove flag boolean --- includes/CLI/Plugin_Check_Command.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index e9cf63ff9..3e9331098 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -674,6 +674,8 @@ private function has_runtime_check( array $checks ) { * @param int $error_severity Error severity level. * @param int $warning_severity Warning severity level. * @param bool $include_low_severity_errors Include less level of severity issues as warning. + * + * @SuppressWarnings(PHPMD.BooleanArgumentFlag) * @return array Filtered results. */ private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity, $include_low_severity_errors = false ) { From 2df30000cf2fe6b16db3f1b8e263d3073b4f59a8 Mon Sep 17 00:00:00 2001 From: David Perez Date: Wed, 16 Oct 2024 23:36:19 +0200 Subject: [PATCH 14/23] Update includes/CLI/Plugin_Check_Command.php Co-authored-by: Felix Arntz --- includes/CLI/Plugin_Check_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index 3e9331098..0cd8d9290 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -114,7 +114,7 @@ public function __construct( Plugin_Context $plugin_context ) { * : Warning severity level. * * [--include-low-severity-errors] - * : Include less level of severity issues as warning. + * : Include errors with lower severity than the threshold as warnings. * * [--slug=] * : Slug to override the default. From 37fd096a98e66eb447d10e7b3ffdd6285394bd53 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Wed, 16 Oct 2024 23:44:55 +0200 Subject: [PATCH 15/23] suggested changes --- includes/CLI/Plugin_Check_Command.php | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index 0cd8d9290..a02cb8e72 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -151,7 +151,7 @@ public function check( $args, $assoc_args ) { 'severity' => '', 'error-severity' => '', 'warning-severity' => '', - 'include-low-severity-errors' => '', + 'include-low-severity-errors' => false, 'slug' => '', ) ); @@ -670,33 +670,30 @@ private function has_runtime_check( array $checks ) { * * @since 1.1.0 * - * @param array $results Check results. - * @param int $error_severity Error severity level. - * @param int $warning_severity Warning severity level. + * @param array $results Check results. + * @param int $error_severity Error severity level. + * @param int $warning_severity Warning severity level. * @param bool $include_low_severity_errors Include less level of severity issues as warning. - * + * * @SuppressWarnings(PHPMD.BooleanArgumentFlag) * @return array Filtered results. */ private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity, $include_low_severity_errors = false ) { - $errors = array(); + $errors = array(); + $warnings = array(); + foreach ( $results as $item ) { if ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity ) { $errors[] = $item; } elseif ( $include_low_severity_errors && $item['severity'] < $error_severity ) { $item['type'] = 'WARNING'; $item['severity'] = 10; - $errors[] = $item; + $warnings[] = $item; + } elseif ( 'WARNING' === $item['type'] && $item['severity'] >= $warning_severity ) { + $warnings[] = $item; } } - $warnings = array_filter( - $results, - function ( $item ) use ( $warning_severity ) { - return ( 'WARNING' === $item['type'] && $item['severity'] >= $warning_severity ); - } - ); - return array_merge( $errors, $warnings ); } } From a62fd0bef2617771d44eb98503f9970e70679c75 Mon Sep 17 00:00:00 2001 From: David Perez Date: Thu, 17 Oct 2024 22:30:31 +0200 Subject: [PATCH 16/23] Update includes/CLI/Plugin_Check_Command.php Co-authored-by: Mukesh Panchal --- includes/CLI/Plugin_Check_Command.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index a02cb8e72..f636572fa 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -673,10 +673,10 @@ private function has_runtime_check( array $checks ) { * @param array $results Check results. * @param int $error_severity Error severity level. * @param int $warning_severity Warning severity level. - * @param bool $include_low_severity_errors Include less level of severity issues as warning. + * @param bool $include_low_severity_errors Include less level of severity issues as warning. Default false. + * @return array Filtered results. * * @SuppressWarnings(PHPMD.BooleanArgumentFlag) - * @return array Filtered results. */ private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity, $include_low_severity_errors = false ) { $errors = array(); From 16a33d1b2cc949a6990b7a861311dec70049ec7b Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Thu, 17 Oct 2024 22:32:10 +0200 Subject: [PATCH 17/23] fix conditional --- includes/CLI/Plugin_Check_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index f636572fa..547373d5a 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -685,7 +685,7 @@ private function get_filtered_results_by_severity( $results, $error_severity, $w foreach ( $results as $item ) { if ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity ) { $errors[] = $item; - } elseif ( $include_low_severity_errors && $item['severity'] < $error_severity ) { + } elseif ( $include_low_severity_errors && 'ERROR' === $item['type'] && $item['severity'] < $error_severity ) { $item['type'] = 'WARNING'; $item['severity'] = 10; $warnings[] = $item; From 57950b15e21831bbb860494b39cd71275973b640 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Fri, 18 Oct 2024 17:56:28 +0200 Subject: [PATCH 18/23] changed to ERROR_EXTRA as suggested --- includes/CLI/Plugin_Check_Command.php | 5 ++--- tests/behat/features/plugin-check-severity.feature | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index 547373d5a..28e8acf36 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -686,9 +686,8 @@ private function get_filtered_results_by_severity( $results, $error_severity, $w if ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity ) { $errors[] = $item; } elseif ( $include_low_severity_errors && 'ERROR' === $item['type'] && $item['severity'] < $error_severity ) { - $item['type'] = 'WARNING'; - $item['severity'] = 10; - $warnings[] = $item; + $item['type'] = 'ERROR_EXTRA'; + $warnings[] = $item; } elseif ( 'WARNING' === $item['type'] && $item['severity'] >= $warning_severity ) { $warnings[] = $item; } diff --git a/tests/behat/features/plugin-check-severity.feature b/tests/behat/features/plugin-check-severity.feature index 0f6494881..5b0a41baa 100644 --- a/tests/behat/features/plugin-check-severity.feature +++ b/tests/behat/features/plugin-check-severity.feature @@ -199,11 +199,11 @@ Feature: Test that the severity level in plugin check works. """ And STDOUT should contain: """ - default_readme_text,WARNING,7 + WordPress.WP.AlternativeFunctions.rand_mt_rand,ERROR_EXTRA,5 """ And STDOUT should contain: """ - upgrade_notice_limit,WARNING,10 + WordPress.Security.EscapeOutput.OutputNotEscaped,ERROR_EXTRA,5 """ When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity --severity=10` From 10ab255512f7496ed5a01eabdc93e1c4a909c615 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Fri, 18 Oct 2024 18:00:33 +0200 Subject: [PATCH 19/23] move to warnings --- includes/CLI/Plugin_Check_Command.php | 9 +++++---- tests/behat/features/plugin-check-severity.feature | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index 28e8acf36..f2ca56a14 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -673,10 +673,10 @@ private function has_runtime_check( array $checks ) { * @param array $results Check results. * @param int $error_severity Error severity level. * @param int $warning_severity Warning severity level. - * @param bool $include_low_severity_errors Include less level of severity issues as warning. Default false. - * @return array Filtered results. + * @param bool $include_low_severity_errors Include less level of severity issues as warning. * * @SuppressWarnings(PHPMD.BooleanArgumentFlag) + * @return array Filtered results. */ private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity, $include_low_severity_errors = false ) { $errors = array(); @@ -686,8 +686,9 @@ private function get_filtered_results_by_severity( $results, $error_severity, $w if ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity ) { $errors[] = $item; } elseif ( $include_low_severity_errors && 'ERROR' === $item['type'] && $item['severity'] < $error_severity ) { - $item['type'] = 'ERROR_EXTRA'; - $warnings[] = $item; + $item['type'] = 'WARNING'; + $item['severity'] = 10; + $warnings[] = $item; } elseif ( 'WARNING' === $item['type'] && $item['severity'] >= $warning_severity ) { $warnings[] = $item; } diff --git a/tests/behat/features/plugin-check-severity.feature b/tests/behat/features/plugin-check-severity.feature index 5b0a41baa..9fbe4f433 100644 --- a/tests/behat/features/plugin-check-severity.feature +++ b/tests/behat/features/plugin-check-severity.feature @@ -199,11 +199,11 @@ Feature: Test that the severity level in plugin check works. """ And STDOUT should contain: """ - WordPress.WP.AlternativeFunctions.rand_mt_rand,ERROR_EXTRA,5 + WordPress.WP.AlternativeFunctions.rand_mt_rand,WARNING,10 """ And STDOUT should contain: """ - WordPress.Security.EscapeOutput.OutputNotEscaped,ERROR_EXTRA,5 + WordPress.Security.EscapeOutput.OutputNotEscaped,WARNING,10 """ When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity --severity=10` From 8967e539c2b4fb6720e2c704b9c83d7b202007ee Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Thu, 7 Nov 2024 23:13:26 +0100 Subject: [PATCH 20/23] errors-low-severity and warnings-low-severity --- includes/CLI/Plugin_Check_Command.php | 46 +++++++++++-------- .../features/plugin-check-severity.feature | 18 +++++++- 2 files changed, 43 insertions(+), 21 deletions(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index f2ca56a14..4728aec16 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -114,7 +114,10 @@ public function __construct( Plugin_Context $plugin_context ) { * : Warning severity level. * * [--include-low-severity-errors] - * : Include errors with lower severity than the threshold as warnings. + * : Include errors with lower severity than the threshold as other type. + * + * [--include-low-severity-warnings] + * : Include errors with lower severity than the threshold as other type. * * [--slug=] * : Slug to override the default. @@ -143,16 +146,17 @@ 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' => '', - 'include-low-severity-errors' => false, - 'slug' => '', + 'checks' => '', + 'format' => 'table', + 'ignore-warnings' => false, + 'ignore-errors' => false, + 'include-experimental' => false, + 'severity' => '', + 'error-severity' => '', + 'warning-severity' => '', + 'include-low-severity-errors' => false, + 'include-low-severity-warnings' => false, + 'slug' => '', ) ); @@ -260,9 +264,10 @@ 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']; - $include_low_severity_errors = ! empty( $options['include-low-severity-errors'] ) ? true : false; + $error_severity = ! empty( $options['error-severity'] ) ? $options['error-severity'] : $options['severity']; + $warning_severity = ! empty( $options['warning-severity'] ) ? $options['warning-severity'] : $options['severity']; + $include_low_severity_errors = ! empty( $options['include-low-severity-errors'] ) ? true : false; + $include_low_severity_warnings = ! empty( $options['include-low-severity-warnings'] ) ? true : false; // Print the formatted results. // Go over all files with errors first and print them, combined with any warnings in the same file. @@ -275,7 +280,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 ), $include_low_severity_errors ); + $file_results = $this->get_filtered_results_by_severity( $file_results, intval( $error_severity ), intval( $warning_severity ), $include_low_severity_errors, $include_low_severity_warnings ); } if ( ! empty( $file_results ) ) { @@ -674,11 +679,12 @@ private function has_runtime_check( array $checks ) { * @param int $error_severity Error severity level. * @param int $warning_severity Warning severity level. * @param bool $include_low_severity_errors Include less level of severity issues as warning. + * @param bool $include_low_severity_warnings Include less level of severity issues as warning. * * @SuppressWarnings(PHPMD.BooleanArgumentFlag) * @return array Filtered results. */ - private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity, $include_low_severity_errors = false ) { + private function get_filtered_results_by_severity( $results, $error_severity, $warning_severity, $include_low_severity_errors = false, $include_low_severity_warnings = false ) { $errors = array(); $warnings = array(); @@ -686,9 +692,11 @@ private function get_filtered_results_by_severity( $results, $error_severity, $w if ( 'ERROR' === $item['type'] && $item['severity'] >= $error_severity ) { $errors[] = $item; } elseif ( $include_low_severity_errors && 'ERROR' === $item['type'] && $item['severity'] < $error_severity ) { - $item['type'] = 'WARNING'; - $item['severity'] = 10; - $warnings[] = $item; + $item['type'] = 'ERRORS_LOW_SEVERITY'; + $errors[] = $item; + } elseif ( $include_low_severity_warnings && 'WARNING' === $item['type'] && $item['severity'] < $warning_severity ) { + $item['type'] = 'WARNINGS_LOW_SEVERITY'; + $warnings[] = $item; } elseif ( 'WARNING' === $item['type'] && $item['severity'] >= $warning_severity ) { $warnings[] = $item; } diff --git a/tests/behat/features/plugin-check-severity.feature b/tests/behat/features/plugin-check-severity.feature index 9fbe4f433..d39c17110 100644 --- a/tests/behat/features/plugin-check-severity.feature +++ b/tests/behat/features/plugin-check-severity.feature @@ -199,11 +199,25 @@ Feature: Test that the severity level in plugin check works. """ And STDOUT should contain: """ - WordPress.WP.AlternativeFunctions.rand_mt_rand,WARNING,10 + WordPress.WP.AlternativeFunctions.rand_mt_rand,ERRORS_LOW_SEVERITY,5 """ And STDOUT should contain: """ - WordPress.Security.EscapeOutput.OutputNotEscaped,WARNING,10 + WordPress.Security.EscapeOutput.OutputNotEscaped,ERRORS_LOW_SEVERITY,5 + """ + + When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity --warning-severity=7 --include-low-severity-warnings` + Then STDOUT should contain: + """ + allow_unfiltered_uploads_detected,ERROR,7 + """ + And STDOUT should contain: + """ + upgrade_notice_limit,WARNINGS_LOW_SEVERITY,5 + """ + And STDOUT should contain: + """ + default_readme_text,WARNING,7 """ When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity --severity=10` From ed6d75f360608aac3d6eaaeebf4557e5c5b828f6 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Fri, 8 Nov 2024 17:00:34 +0100 Subject: [PATCH 21/23] fix error and severity in warnings --- includes/CLI/Plugin_Check_Command.php | 2 +- tests/behat/features/plugin-check-severity.feature | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index 79bcacbc1..4c0bc288e 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -272,7 +272,7 @@ static function ( $dirs ) use ( $excluded_files ) { $file_results = $this->flatten_file_results( array(), $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 ), $include_low_severity_errors, $include_low_severity_warnings ); } if ( ! empty( $file_results ) ) { diff --git a/tests/behat/features/plugin-check-severity.feature b/tests/behat/features/plugin-check-severity.feature index 88481da25..3e82d13f9 100644 --- a/tests/behat/features/plugin-check-severity.feature +++ b/tests/behat/features/plugin-check-severity.feature @@ -217,7 +217,7 @@ Feature: Test that the severity level in plugin check works. """ And STDOUT should contain: """ - default_readme_text,WARNING,7 + default_readme_text,ERROR,7 """ When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity --severity=10` From c4541ccf8b14145dd1f78e738b6435e30a68a461 Mon Sep 17 00:00:00 2001 From: davidperezgar Date: Sat, 9 Nov 2024 10:35:53 +0100 Subject: [PATCH 22/23] fix comment --- includes/CLI/Plugin_Check_Command.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index 4c0bc288e..e512fad6e 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -115,7 +115,7 @@ public function __construct( Plugin_Context $plugin_context ) { * : Include errors with lower severity than the threshold as other type. * * [--include-low-severity-warnings] - * : Include errors with lower severity than the threshold as other type. + * : Include warnings with lower severity than the threshold as other type. * * [--slug=] * : Slug to override the default. From 6268281b13e088cf08f87c841c7ccca1272cf393 Mon Sep 17 00:00:00 2001 From: Nilambar Sharma Date: Tue, 12 Nov 2024 11:41:29 +0545 Subject: [PATCH 23/23] Fix spacing issues in function docs Co-authored-by: Felix Arntz --- includes/CLI/Plugin_Check_Command.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/CLI/Plugin_Check_Command.php b/includes/CLI/Plugin_Check_Command.php index e512fad6e..0529611be 100644 --- a/includes/CLI/Plugin_Check_Command.php +++ b/includes/CLI/Plugin_Check_Command.php @@ -636,10 +636,10 @@ private function display_results( $formatter, $file_name, $file_results ) { * * @since 1.1.0 * - * @param array $results Check results. - * @param int $error_severity Error severity level. - * @param int $warning_severity Warning severity level. - * @param bool $include_low_severity_errors Include less level of severity issues as warning. + * @param array $results Check results. + * @param int $error_severity Error severity level. + * @param int $warning_severity Warning severity level. + * @param bool $include_low_severity_errors Include less level of severity issues as warning. * @param bool $include_low_severity_warnings Include less level of severity issues as warning. * * @SuppressWarnings(PHPMD.BooleanArgumentFlag)