|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 /* 00003 * $Id: Parser.php,v 1.2 2010/12/14 17:36:00 moodlerobot Exp $ 00004 * 00005 * Copyright(c) 2004-2006, SpikeSource Inc. All Rights Reserved. 00006 * Licensed under the Open Software License version 2.1 00007 * (See http://www.spikesource.com/license.html) 00008 */ 00009 ?> 00010 <?php 00011 00012 if(!defined("__PHPCOVERAGE_HOME")) { 00013 define("__PHPCOVERAGE_HOME", dirname(dirname(__FILE__))); 00014 } 00015 require_once __PHPCOVERAGE_HOME . "/conf/phpcoverage.conf.php"; 00016 require_once __PHPCOVERAGE_HOME . "/util/Utility.php"; 00017 00018 00027 define("LINE_TYPE_UNKNOWN", "0"); 00028 define("LINE_TYPE_EXEC", "1"); 00029 define("LINE_TYPE_NOEXEC", "2"); 00030 define("LINE_TYPE_CONT", "3"); 00031 00032 abstract class Parser { 00033 /*{{{ Members */ 00034 00035 protected $totalLines; 00036 protected $coveredLines; 00037 protected $uncoveredLines; 00038 protected $fileRef; 00039 protected $filename; 00040 00041 protected $line; 00042 protected $logger; 00043 00044 /*}}}*/ 00045 /*{{{ public function __construct() */ 00050 public function __construct() { 00051 global $util; 00052 $this->totalLines = 0; 00053 $this->coveredLines = 0; 00054 $this->uncoveredLines = 0; 00055 00056 $this->fileRef = false; 00057 $this->line = false; 00058 $this->lineType = false; 00059 00060 $this->logger = $util->getLogger(); 00061 } 00062 00063 /*}}}*/ 00064 /*{{{ public abstract function parse() */ 00065 00073 public function parse($filename) { 00074 $this->filename = $filename; 00075 $ret = $this->openFileReadOnly(); 00076 if(!$ret) { 00077 die("Error: Cannot open file: $this->filename \n"); 00078 } 00079 } 00080 00081 /*}}}*/ 00082 /*{{{ protected abstract function processLine() */ 00083 00092 protected abstract function processLine($line); 00093 00094 /*}}}*/ 00095 /*{{{ public function getLine() */ 00096 00103 public function getLine() { 00104 if(!feof($this->fileRef)) { 00105 $this->line = fgets($this->fileRef); 00106 $this->processLine($this->line); 00107 } 00108 else { 00109 fclose($this->fileRef); 00110 $this->line = false; 00111 } 00112 return $this->line; 00113 } 00114 00115 /*}}}*/ 00116 /*{{{ public abstract function getLineType() */ 00117 00131 public abstract function getLineType(); 00132 00133 /*}}}*/ 00134 /*{{{ public function getLineTypeStr() */ 00135 00143 public function getLineTypeStr($lineType) { 00144 if($lineType == LINE_TYPE_EXEC) { 00145 return "LINE_TYPE_EXEC"; 00146 } 00147 else if($lineType == LINE_TYPE_NOEXEC) { 00148 return "LINE_TYPE_NOEXEC"; 00149 } 00150 else if($lineType == LINE_TYPE_CONT) { 00151 return "LINE_TYPE_CONT"; 00152 } 00153 else { 00154 return "LINE_TYPE_UNKNOWN"; 00155 } 00156 } 00157 00158 /*}}}*/ 00159 /*{{{ protected function openFileReadOnly() */ 00160 00167 protected function openFileReadOnly() { 00168 $this->fileRef = fopen($this->filename, "r"); 00169 return $this->fileRef !== false; 00170 } 00171 00172 /*}}}*/ 00173 /*{{{ public function getTotalLines() */ 00174 00181 public function getTotalLines() { 00182 return $this->totalLines; 00183 } 00184 00185 /*}}}*/ 00186 /*{{{ public function getCoveredLines() */ 00187 00194 public function getCoveredLines() { 00195 return $this->coveredLines; 00196 } 00197 00198 /*}}}*/ 00199 /*{{{ public function getUncoveredLines() */ 00200 00210 public function getUncoveredLines() { 00211 return $this->uncoveredLines; 00212 } 00213 00214 /*}}}*/ 00215 } 00216 00217 ?>