/**
  * Collect coverage from XML object.
  *
  * @param  SimpleXMLElement                                  $xml     Clover XML object.
  * @param  string                                            $rootDir Path to src directory.
  * @return \Contrib\Bundle\CoverallsV1Bundle\Entity\JsonFile
  */
 public function collect(\SimpleXMLElement $xml, $rootDir)
 {
     $root = $rootDir . DIRECTORY_SEPARATOR;
     if (!isset($this->jsonFile)) {
         $this->jsonFile = new JsonFile();
     }
     // overwrite if run_at has already been set
     $runAt = $this->collectRunAt($xml);
     $this->jsonFile->setRunAt($runAt);
     $xpaths = array('/coverage/project/file', '/coverage/project/package/file');
     foreach ($xpaths as $xpath) {
         foreach ($xml->xpath($xpath) as $file) {
             $srcFile = $this->collectFileCoverage($file, $root);
             if ($srcFile !== null) {
                 $this->jsonFile->addSourceFile($srcFile);
             }
         }
     }
     return $this->jsonFile;
 }