コード例 #1
0
ファイル: CS.php プロジェクト: rodrigorm/phpqa-patch
 public function execute($xml, $patch, $prefix)
 {
     $result = array();
     $cs = simplexml_load_file(realpath($xml));
     $parser = new DiffParser();
     $patch = $parser->parse(file_get_contents($patch));
     $changes = array();
     foreach ($patch as $diff) {
         $file = substr($diff->getTo(), 2);
         $changes[$file] = array();
         foreach ($diff->getChunks() as $chunk) {
             $lineNr = $chunk->getEnd();
             foreach ($chunk->getLines() as $line) {
                 if ($line->getType() == Line::ADDED) {
                     $changes[$file][] = $lineNr;
                 }
                 if ($line->getType() != Line::REMOVED) {
                     $lineNr++;
                 }
             }
         }
     }
     foreach ($cs->file as $file) {
         $path = str_replace($prefix, '', $file->attributes()->name);
         foreach ($file->error as $error) {
             $line = (int) $error->attributes()->line;
             if (isset($changes[$path]) && in_array($line, $changes[$path])) {
                 $result[] = array('file' => $path, 'line' => $line, 'severity' => (string) $error->attributes()->severity, 'message' => (string) $error->attributes()->message);
             }
         }
     }
     return $result;
 }
コード例 #2
0
 /** @test **/
 function it_gets_files_with_added_code()
 {
     $diff = $this->getDiff();
     $parser = new Parser();
     $filter = new DiffOutputFilter('/path', $parser->parse($diff));
     $this->assertEquals(['/path/file_a.php', '/path/file_b.php', '/path/file_c.php'], $filter->getFilesWithAddedCode());
 }
コード例 #3
0
ファイル: Diff.php プロジェクト: braskit/diff
 /**
  * Diffs two strings and returns an object graph.
  *
  * @param $one
  * @param $two
  *
  * @return DiffOutput|null
  */
 public function diffStrings($one, $two)
 {
     $unified = $this->getUnifiedDiff($one, $two);
     $diffs = $this->parser->parse($unified);
     if (isset($diffs[0])) {
         return $diffs[0];
     }
     return null;
 }
コード例 #4
0
ファイル: ParserTest.php プロジェクト: cruni505/prestomed
 public function testParseWithMultipleChunks()
 {
     $content = file_get_contents(__DIR__ . '/fixtures/patch2.txt');
     $diffs = $this->parser->parse($content);
     $this->assertCount(1, $diffs);
     $chunks = $diffs[0]->getChunks();
     $this->assertCount(3, $chunks);
     $this->assertEquals(20, $chunks[0]->getStart());
     $this->assertEquals(320, $chunks[1]->getStart());
     $this->assertEquals(600, $chunks[2]->getStart());
     $this->assertCount(5, $chunks[0]->getLines());
     $this->assertCount(5, $chunks[1]->getLines());
     $this->assertCount(5, $chunks[2]->getLines());
 }
コード例 #5
0
ファイル: Humbug.php プロジェクト: rodrigorm/phpqa-patch
 public function execute($json, $patch, $prefix)
 {
     $result = array();
     $humbug = json_decode(file_get_contents(realpath($json)), true);
     $parser = new DiffParser();
     $patch = $parser->parse(file_get_contents($patch));
     $changes = array();
     foreach ($patch as $diff) {
         $file = substr($diff->getTo(), 2);
         $changes[$file] = array();
         foreach ($diff->getChunks() as $chunk) {
             $lineNr = $chunk->getEnd();
             foreach ($chunk->getLines() as $line) {
                 if ($line->getType() == Line::ADDED) {
                     $changes[$file][] = $lineNr;
                 }
                 if ($line->getType() != Line::REMOVED) {
                     $lineNr++;
                 }
             }
         }
     }
     $result = array('summary' => $humbug['summary']);
     $types = array('uncovered', 'escaped', 'errored', 'timeouts', 'killed');
     foreach ($types as $type) {
         $result[$type] = array();
         foreach ($humbug[$type] as $violation) {
             $path = str_replace($prefix, '', $violation['file']);
             $line = (int) $violation['line'];
             if (isset($changes[$path]) && in_array($line, $changes[$path])) {
                 $result[$type][] = $violation;
             }
         }
     }
     $result['summary']['notests'] = count($result['uncovered']);
     $result['summary']['escapes'] = count($result['escaped']);
     $result['summary']['errors'] = count($result['errored']);
     $result['summary']['timeouts'] = count($result['timeouts']);
     $result['summary']['kills'] = count($result['killed']);
     $result['summary']['total'] = $result['summary']['notests'] + $result['summary']['escapes'] + $result['summary']['errors'] + $result['summary']['timeouts'] + $result['summary']['kills'];
     return $result;
 }
コード例 #6
0
ファイル: PatchCoverage.php プロジェクト: vpx/phpcov
 /**
  * @param  string $coverage
  * @param  string $patch
  * @param  string $prefix
  * @return array
  */
 public function execute($coverage, $patch, $prefix)
 {
     $result = array('numChangedLinesThatAreExecutable' => 0, 'numChangedLinesThatWereExecuted' => 0, 'changedLinesThatWereNotExecuted' => array());
     $coverage = (include $coverage);
     $coverage = $coverage->getData();
     $parser = new DiffParser();
     $patch = $parser->parse(file_get_contents($patch));
     $changes = array();
     foreach ($patch as $diff) {
         $file = substr($diff->getFrom(), 2);
         $changes[$file] = array();
         foreach ($diff->getChunks() as $chunk) {
             $lineNr = $chunk->getStart();
             foreach ($chunk->getLines() as $line) {
                 if ($line->getType() == Line::ADDED) {
                     $changes[$file][] = $lineNr;
                 }
                 if ($line->getType() != Line::REMOVED) {
                     $lineNr++;
                 }
             }
         }
     }
     foreach ($changes as $file => $lines) {
         $key = $prefix . $file;
         foreach ($lines as $line) {
             if (isset($coverage[$key][$line]) && is_array($coverage[$key][$line])) {
                 $result['numChangedLinesThatAreExecutable']++;
                 if (empty($coverage[$key][$line])) {
                     if (!isset($result['changedLinesThatWereNotExecuted'][$file])) {
                         $result['changedLinesThatWereNotExecuted'][$file] = array();
                     }
                     $result['changedLinesThatWereNotExecuted'][$file][] = $line;
                 } else {
                     $result['numChangedLinesThatWereExecuted']++;
                 }
             }
         }
     }
     return $result;
 }
コード例 #7
0
ファイル: CPD.php プロジェクト: rodrigorm/phpqa-patch
 public function execute($xml, $patch, $prefix)
 {
     $result = array();
     $cpd = simplexml_load_file(realpath($xml));
     $parser = new DiffParser();
     $patch = $parser->parse(file_get_contents($patch));
     $changes = array();
     foreach ($patch as $diff) {
         $file = substr($diff->getTo(), 2);
         $changes[$file] = array();
         foreach ($diff->getChunks() as $chunk) {
             $lineNr = $chunk->getEnd();
             foreach ($chunk->getLines() as $line) {
                 if ($line->getType() == Line::ADDED) {
                     $changes[$file][] = $lineNr;
                 }
                 if ($line->getType() != Line::REMOVED) {
                     $lineNr++;
                 }
             }
         }
     }
     foreach ($cpd->duplication as $duplication) {
         foreach ($duplication->file as $file) {
             $path = str_replace($prefix, '', $file->attributes()->path);
             $beginline = (int) $file->attributes()->line;
             $endline = $beginline + ((int) $duplication->attributes()->lines - 1);
             $lines = array();
             for ($line = $beginline; $line <= $endline; $line++) {
                 if (isset($changes[$path]) && in_array($line, $changes[$path])) {
                     $lines[] = $line;
                 }
             }
             if (empty($lines)) {
                 continue;
             }
             $result[] = $duplication;
         }
     }
     return $result;
 }
コード例 #8
0
 public function process()
 {
     $git = new Git($this->repository);
     $parser = new Parser();
     $currentBranch = $git->getCurrentBranch();
     $revisions = $git->getRevisions();
     $count = count($revisions);
     if ($count < 3) {
         return;
     }
     if ($this->progressHelper !== null) {
         $this->progressHelper->start($this->output, count($revisions) - 2);
     }
     for ($i = 1; $i < $count - 1; $i++) {
         $diff = $parser->parse($git->getDiff($revisions[$i - 1]['sha1'], $revisions[$i]['sha1']));
         $git->checkout($revisions[$i]['sha1']);
         $this->processRevision($revisions[$i]['sha1'], $revisions[$i]['message'], $diff, $this->findFiles());
         if ($this->progressHelper !== null) {
             $this->progressHelper->advance();
         }
     }
     $git->checkout($currentBranch);
 }
コード例 #9
0
 /**
  * @param string $diff
  * @param array  $expected
  * @dataProvider diffProvider
  * @covers       SebastianBergmann\Diff\Parser::parse
  */
 public function testParser($diff, $expected)
 {
     $parser = new Parser();
     $result = $parser->parse($diff);
     $this->assertEquals($expected, $result);
 }
コード例 #10
0
ファイル: Lint.php プロジェクト: wouterj/docbot
 private function getReporter()
 {
     if ($this->diff) {
         list($commitA, $commitB) = explode('...', $this->diff, 2);
         $git = new Git(getcwd());
         $diffParser = new Parser();
         $diff = $diffParser->parse($git->getDiff($commitA, $commitB));
         return new Reporter\DiffFilter($this->getContainer()->get('reporter'), $diff);
     }
     return $this->getContainer()->get('reporter');
 }
コード例 #11
0
ファイル: Command.php プロジェクト: ricardorsierra/php-hound
 /**
  * Create a DiffOutputFilter based on a git-diff param.
  * @param string $gitDiff git diff arguments.
  * @return DiffOutputFilter filter instance.
  */
 protected function getGitDiffFilter($gitDiff)
 {
     $analysedPaths = $this->getAnalysedPaths();
     $gitPath = array_shift($analysedPaths);
     if (!is_dir($gitPath)) {
         $gitPath = dirname($gitPath);
     }
     $git = new Git($gitPath);
     $executeMethod = new ReflectionMethod($git, 'execute');
     $executeMethod->setAccessible(true);
     $gitRoot = trim(implode("\n", $executeMethod->invoke($git, 'git rev-parse --show-toplevel')));
     list($base, $changed) = explode('..', $gitDiff);
     $diff = $git->getDiff($base, $changed);
     $diffParser = new Parser();
     return new DiffOutputFilter($gitRoot, $diffParser->parse($diff));
 }