jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/386677 )
Change subject: cover: Avoid division by zero warnings ...................................................................... cover: Avoid division by zero warnings Change-Id: I1376a9d073113057c9efedcbd8e44d9eca04cf82 --- M org/wikimedia/doc/cover/index.php 1 file changed, 14 insertions(+), 9 deletions(-) Approvals: Krinkle: Looks good to me, approved jenkins-bot: Verified diff --git a/org/wikimedia/doc/cover/index.php b/org/wikimedia/doc/cover/index.php index 865e9b0..d82a623 100644 --- a/org/wikimedia/doc/cover/index.php +++ b/org/wikimedia/doc/cover/index.php @@ -79,17 +79,22 @@ $xml = new SimpleXMLElement( $contents ); $metrics = $xml->project->metrics; - $percent = ( - (int)$metrics['coveredmethods'] + - (int)$metrics['coveredconditionals'] + - (int)$metrics['coveredstatements'] + - (int)$metrics['coveredelements'] - ) / ( - (int)$metrics['methods'] + + $total = (int)$metrics['methods'] + (int)$metrics['conditionals'] + (int)$metrics['statements'] + - (int)$metrics['elements'] - ); + (int)$metrics['elements']; + if ( $total === 0 ) { + // Avoid division by 0 warnings, and treat 0/0 as 100% + // to match the PHPUnit behavior + $percent = 1; + } else { + $percent = ( + (int)$metrics['coveredmethods'] + + (int)$metrics['coveredconditionals'] + + (int)$metrics['coveredstatements'] + + (int)$metrics['coveredelements'] + ) / $total; + } // TODO: Figure out how to get a more friendly name return [ 'percent' => $percent * 100, -- To view, visit https://gerrit.wikimedia.org/r/386677 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I1376a9d073113057c9efedcbd8e44d9eca04cf82 Gerrit-PatchSet: 2 Gerrit-Project: integration/docroot Gerrit-Branch: master Gerrit-Owner: Legoktm <lego...@member.fsf.org> Gerrit-Reviewer: Hashar <has...@free.fr> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Paladox <thomasmulhall...@yahoo.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits