jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/402174 )

Change subject: Safely handle incomplete clover.xml files
......................................................................


Safely handle incomplete clover.xml files

The script to convert cobertura reports into clover format (863aceaf408)
doesn't include everything, so check that XML properties are isset()
before trying to read them.

Change-Id: I51a0e12dd7d3e9f88e59b0a6d5f7df0b92b85c16
---
M shared/CoveragePage.php
1 file changed, 18 insertions(+), 10 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/shared/CoveragePage.php b/shared/CoveragePage.php
index a48f996..cd67474 100644
--- a/shared/CoveragePage.php
+++ b/shared/CoveragePage.php
@@ -98,23 +98,31 @@
                        return false;
                }
 
+               $types = [ 'methods', 'conditionals', 'statements', 'elements' 
];
+               $total = 0;
                $xml = new SimpleXMLElement( $contents );
                $metrics = $xml->project->metrics;
-               $total = (int)$metrics['methods'] +
-                       (int)$metrics['conditionals'] +
-                       (int)$metrics['statements'] +
-                       (int)$metrics['elements'];
+               // A proper clover.xml file will have all of the four types, but
+               // we're also converting other types into clover.xml, that don't
+               // have all the keys we expect. Using isset() should make this 
safe.
+               foreach ( $types as $type ) {
+                       if ( isset( $metrics[$type] ) ) {
+                               $total += (int)$metrics[$type];
+                       }
+               }
                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;
+                       $covered = 0;
+                       foreach ( $types as $type ) {
+                               if ( isset( $metrics["covered$type"] ) ) {
+                                       $covered += 
(int)$metrics["covered$type"];
+                               }
+
+                       }
+                       $percent = $covered / $total;
                }
                // TODO: Figure out how to get a more friendly name
                return [

-- 
To view, visit https://gerrit.wikimedia.org/r/402174
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I51a0e12dd7d3e9f88e59b0a6d5f7df0b92b85c16
Gerrit-PatchSet: 1
Gerrit-Project: integration/docroot
Gerrit-Branch: master
Gerrit-Owner: Legoktm <lego...@member.fsf.org>
Gerrit-Reviewer: Hashar <has...@free.fr>
Gerrit-Reviewer: Legoktm <lego...@member.fsf.org>
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

Reply via email to