Esempio n. 1
0
 public function locateUnits($file)
 {
     if (false === ($fh = fopen($file, 'r'))) {
         /* Oops. The file cannot be opened for reading. */
         throw new Exception("Unable to open file '{$file}' for reading.");
     }
     $row = 0;
     $in_comment = false;
     $in_php = false;
     while (($line = fgets($fh)) !== false) {
         $row++;
         $line = SourceParser::stripSingle($line);
         if (1 == preg_match('/\\<\\?(php)?/', $line)) {
             $in_php = true;
         }
         if (1 === preg_match('/\\?\\>/', $line)) {
             $in_php = false;
         }
         if (1 === preg_match('/\\/\\*/', $line)) {
             $in_comment = true;
         }
         if (1 === preg_match('/\\*\\//', $line)) {
             $in_comment = false;
         }
         if ($in_comment || !$in_php) {
             continue;
         }
         if (false !== ($array_pos = $this->findUnit($line))) {
             $this->units[$array_pos]['file'] = $file;
             $this->units[$array_pos]['row'] = $row;
             $this->setFaults($this->units[$array_pos]);
         }
     }
 }
Esempio n. 2
0
 public function extractSource(&$unit)
 {
     $f = $unit['file'];
     if (false === ($fh = @fopen($f, 'r'))) {
         throw new Exception("Unable to open file {$f} for reading.");
     }
     /* Go to right location in file */
     for ($i = 1; $i < $unit['row']; $i++) {
         if (false === @fgets($fh)) {
             throw new Exception("Unable to read file '{$f}'.");
         }
     }
     $source =& $unit['src'];
     $source_strip =& $unit['src_strip'];
     $sloc =& $unit['sloc'];
     $err =& $unit['err'];
     $err = 0;
     $curlies = 0;
     $first_curlie_found = false;
     $in_comment = false;
     do {
         $sloc += 1;
         $line = fgets($fh);
         $line_strip = SourceParser::stripSingle($line);
         $source .= $line;
         $source_strip .= $line_strip;
         if (1 === preg_match('/\\/\\*/', $line_strip)) {
             $in_comment = true;
         }
         if (1 === preg_match('/\\*\\//', $line_strip)) {
             $in_comment = false;
         }
         if ($in_comment) {
             continue;
         }
         if (1 === preg_match('/\\{/', $line_strip)) {
             $first_curlie_found = true;
             $curlies++;
         }
         if (1 === preg_match('/\\}/', $line_strip)) {
             $curlies--;
         }
     } while ((!$first_curlie_found || $curlies != 0) && !feof($fh));
     if ($curlies !== 0) {
         $source = "Unable to parse source code for unit";
         $err = 1;
         $source_strip = false;
         $sloc = -1;
     }
     $source_strip = SourceParser::stripMultiple($source_strip);
 }
Esempio n. 3
0
 /**
  * @dataProvider strip_nsloc_dp
  */
 function testStrip_nsloc($line, $expected_strip)
 {
     $strip = SourceParser::stripMultiple($line);
     $this->assertEquals($expected_strip, $strip);
 }