Skip to content

Commit

Permalink
Check upgrade notice length for all versions
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Jan 17, 2024
1 parent 1dd4f21 commit 987560e
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions includes/Checker/Checks/Plugin_Readme_Check.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,29 @@ private function check_stable_tag( Check_Result $result, string $readme_file, Pa
* @param Parser $parser The Parser object.
*/
private function check_upgrade_notice( Check_Result $result, string $readme_file, Parser $parser ) {
if ( 0 === count( $parser->upgrade_notice ) ) {
$notices = $parser->upgrade_notice;

// Bail if no upgrade notices.
if ( 0 === count( $notices ) ) {
return;
}

$notice = reset( $parser->upgrade_notice );
$exceed_status = false;
$exceed_version = '';

Check warning on line 210 in includes/Checker/Checks/Plugin_Readme_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Readme_Check.php#L209-L210

Added lines #L209 - L210 were not covered by tests

if ( strlen( $notice ) > 300 ) {
$this->add_result_warning_for_file(
$result,
__( 'The upgrade notice exceeds the limit of 300 characters.', 'plugin-check' ),
'upgrade_notice_limit',
$readme_file
);
foreach ( $notices as $version_key => $notice ) {
if ( strlen( $notice ) > 300 ) {
$exceed_status = true;
$exceed_version = $version_key;
break;

Check warning on line 216 in includes/Checker/Checks/Plugin_Readme_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Readme_Check.php#L212-L216

Added lines #L212 - L216 were not covered by tests
}
}

if ( $exceed_status ) {

Check warning on line 220 in includes/Checker/Checks/Plugin_Readme_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Readme_Check.php#L220

Added line #L220 was not covered by tests
/* translators: version */
$message = empty( $exceed_version ) ? __( 'The upgrade notice exceeds the limit of 300 characters.', 'plugin-check' ) : sprintf( __( "The upgrade notice for '%s' exceeds the limit of 300 characters.", 'plugin-check' ), $exceed_version );

Check warning on line 222 in includes/Checker/Checks/Plugin_Readme_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Readme_Check.php#L222

Added line #L222 was not covered by tests

$this->add_result_warning_for_file( $result, $message, 'upgrade_notice_limit', $readme_file );

Check warning on line 224 in includes/Checker/Checks/Plugin_Readme_Check.php

View check run for this annotation

Codecov / codecov/patch

includes/Checker/Checks/Plugin_Readme_Check.php#L224

Added line #L224 was not covered by tests
}
}

Expand Down

0 comments on commit 987560e

Please sign in to comment.