<?php
/*
* $Id: CoverageXmlParser.php 14663 2005-03-23 19:27:27Z npac $
*
* Copyright(c) 2004-2006, SpikeSource Inc. All Rights Reserved.
* Licensed under the Open Software License version 2.1
* (See http://www.spikesource.com/license.html)
*/
?>
<?php
if(!defined("__PHPCOVERAGE_HOME")) {
define("__PHPCOVERAGE_HOME", dirname(dirname(__FILE__)));
}
require_once __PHPCOVERAGE_HOME . "/util/Utility.php";
require_once dirname(__FILE__) . "/BasicXmlParser.php";
/**
* Special parser for SpikePHPCoverage data parsing
* Expect input in following format:
* <spike-phpcoverage>
* <file path="/complete/file/path">
* <line num="10" freq="1"/>
* <line num="12" freq="2"/>
* </file>
* <file path="/another/file/path">
* ...
* </file>
* </spike-phpcoverage>
*
* @author Nimish Pachapurkar <npac@spikesource.com>
* @version $Revision: $
* @package SpikePHPCoverage_Parser
*/
class CoverageXmlParser extends BasicXmlParser {
/*{{{ Members */
protected $_data = array();
protected $_lastFilePath;
/*}}}*/
protected function saveRawDataForFile($filepath, $line) {
global $util;
$tmpDir = $util->getTmpDir();
$filenameHash = "phpcoverage_raw_" . md5($filepath, false);
$xmlFile = $tmpDir . DIRECTORY_SEPARATOR . $filenameHash;
if (!file_exists($xmlFile) && is_writable($tmpDir)) {
file_put_contents($xmlFile, "name:" . $filepath . "\n");
file_put_contents($xmlFile, $line, FILE_APPEND);
} else {
file_put_contents($xmlFile, $line, FILE_APPEND);
}
return $xmlFile;
}
/*{{{ public function startHandler() */
public function startHandler($xp, $name, $attrs) {
switch($name) {
case "FILE":
$fileAttributes = $this->handleAttrTag($name, $attrs);
$this->_lastFilePath = $fileAttributes["PATH"];
if(!isset($this->_data[$this->_lastFilePath])) {
$this->_data[$this->_lastFilePath] = array();
$this->_data[$this->_lastFilePath]['type'] = "__RAW_DATA__";
}
break;
case "LINE":
$lineAttributes = $this->handleAttrTag($name, $attrs);
$lineNumber = (int)$lineAttributes["NUM"];
$location = $this->saveRawDataForFile($this->_lastFilePath, $lineNumber . ":" . (int)$lineAttributes['FREQ'] . "\n");
if (!isset($this->_data[$this->_lastFilePath]['location'])) {
$this->_data[$this->_lastFilePath]['location'] = $location;
}
/*
if(!isset($this->_data[$this->_lastFilePath][$lineNumber])) {
$this->_data[$this->_lastFilePath][$lineNumber] = (int)$lineAttributes["FREQ"];
}
else {
$this->_data[$this->_lastFilePath][$lineNumber] += (int)$lineAttributes["FREQ"];
}
*/
break;
}
}
/*}}}*/
/*{{{ public function getCoverageData() */
/**
* Returns coverage data array from the XML
* Format:
* Array
* (
* [/php/src/remote/RemoteCoverageRecorder.php] => Array
* (
* [220] => 1
* [221] => 1
* )
*
* [/opt/oss/share/apache2/htdocs/web/sample.php] => Array
* (
* [16] => 1
* [18] => 1
* )
* )
*
* @access public
*/
public function getCoverageData() {
return $this->_data;
}
/*}}}*/
}
?>