[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/tests_runner/lib/spikephpcoverage/src/parser/ -> Parser.php (source)

   1  <?php
   2      /*
   3      *  $Id: Parser.php 14009 2005-03-16 17:33:33Z npac $
   4      *  
   5      *  Copyright(c) 2004-2005, SpikeSource Inc. All Rights Reserved.
   6      *  Licensed under the Open Source License version 2.1
   7      *  (See http://www.spikesource.com/license.html)
   8      */
   9  ?>
  10  <?php
  11  
  12      if(!defined("__PHPCOVERAGE_HOME")) {
  13          define("__PHPCOVERAGE_HOME", dirname(dirname(__FILE__)));
  14      }
  15      require_once  __PHPCOVERAGE_HOME . "/conf/phpcoverage.conf.php";
  16      require_once  __PHPCOVERAGE_HOME . "/util/Utility.php";
  17  
  18  
  19      /** 
  20      * Base class for Parsers. 
  21      * 
  22      * @author Nimish Pachapurkar (npac@spikesource.com)
  23      * @version $Revision: 14009 $
  24      * @package tests_runner
  25      */
  26  
  27      define("LINE_TYPE_UNKNOWN", "0");
  28      define("LINE_TYPE_EXEC", "1");
  29      define("LINE_TYPE_NOEXEC", "2");
  30      define("LINE_TYPE_CONT", "3");
  31  
  32      abstract class Parser {
  33          /*{{{ Members */
  34  
  35          protected $totalLines;
  36          protected $coveredLines;
  37          protected $uncoveredLines;
  38          protected $fileRef;
  39          protected $filename;
  40  
  41          protected $line;
  42          protected $logger;
  43  
  44          /*}}}*/
  45          /*{{{ public function __construct() */
  46          /** 
  47          * Constructor 
  48          * @access public
  49          */
  50          public function __construct() {
  51              $this->totalLines = 0;
  52              $this->coveredLines = 0;
  53              $this->uncoveredLines = 0;
  54  
  55              $this->fileRef = false;
  56              $this->line = false;
  57              $this->lineType = false;
  58  
  59              global $util;
  60              $this->logger = $util->getLogger();
  61          }
  62  
  63          /*}}}*/
  64          /*{{{ public abstract function parse() */
  65  
  66          /** 
  67          * Parse a given file 
  68          * 
  69          * @param $filename Full path of the file
  70          * @return FALSE on error.
  71          * @access public
  72          */
  73          public function parse($filename) {
  74              $this->filename = $filename;
  75              $ret = $this->openFileReadOnly();
  76              if(!$ret) {
  77                  die("Error: Cannot open file: $this->filename \n");
  78              }
  79          }
  80  
  81          /*}}}*/
  82          /*{{{ protected abstract function processLine() */
  83  
  84          /** 
  85          * Process the line and classify it into either
  86          * covered and uncovered.
  87          * 
  88          * @param $line 
  89          * @return 
  90          * @access protected
  91          */
  92          protected abstract function processLine($line);
  93  
  94          /*}}}*/
  95          /*{{{ public function getLine() */
  96  
  97          /** 
  98          * Returns the next line from file. 
  99          * 
 100          * @return Next line from file
 101          * @access public
 102          */
 103          public function getLine() {
 104              if(!feof($this->fileRef)) {
 105                  $this->line = fgets($this->fileRef);
 106                  $this->processLine($this->line);
 107              }
 108              else {
 109                  fclose($this->fileRef);
 110                  $this->line = false;
 111              }
 112              return $this->line;
 113          }
 114  
 115          /*}}}*/
 116          /*{{{ public abstract function getLineType() */
 117  
 118          /** 
 119          * Returns the type of last line read.
 120          *
 121          * The type can be either 
 122          *  * LINE_TYPE_EXEC Line that can be executed.
 123          *  * LINE_TYPE_NOEXEC Line that cannot be executed.
 124          *     This includes the variable and function definitions
 125          *     (without initialization), blank lines, non-PHP lines,
 126          *     etc.
 127          * 
 128          * @return Type of last line
 129          * @access public
 130          */
 131          public abstract function getLineType();
 132  
 133          /*}}}*/
 134          /*{{{ public function getLineTypeStr() */
 135  
 136          /** 
 137          * Returns the string representation of LINE_TYPE 
 138          * 
 139          * @param $lineType 
 140          * @return Type of line
 141          * @access public
 142          */
 143          public function getLineTypeStr($lineType) {
 144              if($lineType == LINE_TYPE_EXEC) {
 145                  return "LINE_TYPE_EXEC";
 146              }
 147              else if($lineType == LINE_TYPE_NOEXEC) {
 148                  return "LINE_TYPE_NOEXEC";
 149              }
 150              else if($lineType == LINE_TYPE_CONT) {
 151                  return "LINE_TYPE_CONT";
 152              }
 153              else {
 154                  return "LINE_TYPE_UNKNOWN";
 155              }
 156          }
 157  
 158          /*}}}*/
 159          /*{{{ protected function openFileReadOnly() */
 160  
 161          /** 
 162          * Opens the file to be parsed in Read-only mode 
 163          * 
 164          * @return FALSE on failure.
 165          * @access protected
 166          */
 167          protected function openFileReadOnly() {
 168              $this->fileRef = fopen($this->filename, "r");
 169              return $this->fileRef !== false;
 170          }
 171  
 172          /*}}}*/
 173          /*{{{ public function getTotalLines() */
 174  
 175          /** 
 176          * Returns the total lines (PHP, non-PHP) from a file 
 177          * 
 178          * @return Number of lines
 179          * @access public
 180          */
 181          public function getTotalLines() {
 182              return $this->totalLines;
 183          }
 184  
 185          /*}}}*/
 186          /*{{{ public function getCoveredLines() */
 187  
 188          /** 
 189          * Returns the number of covered PHP lines
 190          * 
 191          * @return Number of covered lines
 192          * @access public
 193          */
 194          public function getCoveredLines() {
 195              return $this->coveredLines;
 196          }
 197  
 198          /*}}}*/
 199          /*{{{ public function getUncoveredLines() */
 200  
 201          /** 
 202          * Returns the number of uncovered PHP lines 
 203          *
 204          * Note that the sum of covered and uncovered
 205          * lines may not be equal to total lines.
 206          * 
 207          * @return Number of uncovered lines
 208          * @access public
 209          */
 210          public function getUncoveredLines() {
 211              return $this->uncoveredLines;
 212          }
 213  
 214          /*}}}*/
 215      }
 216  
 217  ?>


Generated: Sat Nov 22 03:48:54 2008 Cross-referenced by PHPXref 0.7