示例#1
0
 /**
  * Counts GIT commits per file and range. This is used to track the number
  * of commits on methods or classes.
  *
  * @HACK: I did not manage to convice GIT to omit the diff when using `-L…`
  * – this is why we embed the "qacommit: " string and count its occurence
  * afterwards. This causes GIT to calculate MANY diffs, which are the
  * passed to PHP and thrown away using many string operations. This sucks.
  *
  * @FIX : Can be fixed immediately when we learn how to convince GIT to omit
  * the diffs / patches.
  */
 protected function countGitChangesPerFileRange(Project $project, $file, $from, $to)
 {
     $options = ['log', '--format=format:qacommit: %H', '--no-patch', '-L', "{$from},{$to}:{$file}"];
     $existingResults = $this->shell->exec('git', $options, [0], $project->baseDir);
     return count(array_filter(array_map('trim', explode(PHP_EOL, $existingResults)), function ($line) {
         return strpos($line, 'qacommit: ') === 0;
     }));
 }
示例#2
0
 /**
  * Handle provided directory
  *
  * Optionally an existing result file can be provided
  *
  * If a valid file could be generated the file name is supposed to be
  * returned, otherwise return null.
  *
  * @param Project $project
  * @param string $existingResult
  * @return string
  */
 public function handle(Project $project, $existingResult = null)
 {
     if ($existingResult) {
         // @TODO: Verify file is actually sensible?
         return $existingResult;
     }
     $options = array('--log-pmd=' . ($tmpFile = $this->shell->getTempFile()));
     foreach ($project->excludes as $exclude) {
         $options[] = '--exclude=' . $exclude;
     }
     $this->shell->exec('vendor/bin/phpcpd', array_merge($options, array($project->baseDir)), array(0, 1));
     return $tmpFile;
 }
示例#3
0
 /**
  * Handle provided directory
  *
  * Optionally an existing result file can be provided
  *
  * @param string $dir
  * @param array $excludes
  * @param string $file
  * @return void
  */
 public function handle($dir, array $excludes, $file = null)
 {
     if ($file) {
         // @TODO: Verify file is actually sensible?
         return $file;
     }
     $options = array('--log-pmd=' . ($tmpFile = $this->shell->getTempFile()));
     foreach ($excludes as $exclude) {
         $options[] = '--exclude=' . $exclude;
     }
     $this->shell->exec('vendor/bin/phpcpd', array_merge($options, array($dir)), array(0, 1));
     return $tmpFile;
 }
示例#4
0
 /**
  * Handle provided directory
  *
  * Optionally an existing result file can be provided
  *
  * If a valid file could be generated the file name is supposed to be
  * returned, otherwise return null.
  *
  * @param Project $project
  * @param string $existingResult
  * @return string
  */
 public function handle(Project $project, $existingResult = null)
 {
     if ($existingResult) {
         // @TODO: Verify file is actually sensible?
         return $existingResult;
     }
     $options = array('--dependency-xml=' . ($tmpFile = $this->shell->getTempFile()));
     if ($project->excludes) {
         $options[] = '--ignore=' . implode(',', $project->excludes);
     }
     $this->shell->exec('vendor/bin/pdepend', array_merge($options, array($project->baseDir)));
     return $tmpFile;
 }
示例#5
0
 /**
  * Handle provided directory
  *
  * Optionally an existing result file can be provided
  *
  * @param string $dir
  * @param array $excludes
  * @param string $file
  * @return void
  */
 public function handle($dir, array $excludes, $file = null)
 {
     if ($file) {
         // @TODO: Verify file is actually sensible?
         return $file;
     }
     $options = array('--standard=PSR2', '--extensions=php', '--report-checkstyle=' . ($tmpFile = $this->shell->getTempFile()));
     if ($excludes) {
         $options[] = '--ignore=' . implode(',', $excludes);
     }
     $this->shell->exec('vendor/bin/phpcs', array_merge($options, array($dir)), array(0, 1));
     return $tmpFile;
 }
示例#6
0
 /**
  * Handle provided directory
  *
  * Optionally an existing result file can be provided
  *
  * @param string $dir
  * @param array $excludes
  * @param string $file
  * @return void
  */
 public function handle($dir, array $excludes, $file = null)
 {
     if ($file) {
         // @TODO: Verify file is actually sensible?
         return $file;
     }
     $options = array('--dependency-xml=' . ($tmpFile = $this->shell->getTempFile()));
     if ($excludes) {
         $options[] = '--ignore=' . implode(',', $excludes);
     }
     $this->shell->exec('vendor/bin/pdepend', array_merge($options, array($dir)));
     return $tmpFile;
 }
示例#7
0
 /**
  * Handle provided directory
  *
  * Optionally an existing result file can be provided
  *
  * @param string $dir
  * @param array $excludes
  * @param string $file
  * @return void
  */
 public function handle($dir, array $excludes, $file = null)
 {
     if ($file) {
         // @TODO: Verify file is actually sensible?
         return $file;
     }
     $options = array('--reportfile', $tmpFile = $this->shell->getTempFile());
     if ($excludes) {
         $options[] = '--exclude';
         $options[] = implode(',', $excludes);
     }
     $this->shell->exec('vendor/bin/phpmd', array_merge($options, array($dir, 'xml', 'cleancode,codesize,design')), array(0, 2));
     return $tmpFile;
 }
示例#8
0
 /**
  * Handle provided directory
  *
  * Optionally an existing result file can be provided
  *
  * @param string $dir
  * @param string[] $excludes
  * @param string|null $file
  * @param string|null $coverage
  * @return void
  */
 public function handle($dir, array $excludes, $file = null, $coverage = null)
 {
     if ($file) {
         // @TODO: Verify file is actually sensible?
         return $file;
     }
     $options = array('--summary-xml=' . ($tmpFile = $this->shell->getTempFile()), '--coderank-mode=inheritance,property,method');
     if ($coverage) {
         $options[] = '--coverage-report=' . $coverage;
     }
     if ($excludes) {
         $options[] = '--ignore=' . implode(',', $excludes);
     }
     $this->shell->exec('vendor/bin/pdepend', array_merge($options, array($dir)));
     return $tmpFile;
 }
示例#9
0
 protected function countGitChangesPerFile(Project $project, \DateTime $since = null)
 {
     $options = array('log', '--name-only', '--pretty=format:');
     if ($since) {
         $options[] = '--since=' . $since->format('Y-m-d');
     }
     $gitBasePath = trim($this->shell->exec('git', array('rev-parse', '--show-toplevel'), [0], $project->baseDir));
     $existingResults = $this->shell->exec('git', array_merge($options, array('--', $project->baseDir), array_map(function ($exclude) {
         return ':!' . $exclude;
     }, $project->excludes)), [0], $project->baseDir);
     $existingResults = array_count_values(array_filter(array_map(function ($line) use($gitBasePath) {
         return $gitBasePath . '/' . trim($line);
     }, explode(PHP_EOL, $existingResults))));
     arsort($existingResults, SORT_NUMERIC);
     return $existingResults;
 }
示例#10
0
 /**
  * Handle provided directory
  *
  * Optionally an existing result file can be provided
  *
  * @param string $dir
  * @param array $excludes
  * @param string $file
  * @return void
  */
 public function handle($dir, array $excludes, $file = null)
 {
     $currentDir = getcwd();
     chdir($dir);
     if ($excludes) {
         $finder = new FinderFacade(array($dir), array(), $excludes);
         $excludes = array_map(function ($path) use($dir) {
             $path = substr($path, strlen($dir) + 1);
             return is_file($path) ? $path : $path . '/*';
         }, $finder->findFiles());
         array_unshift($excludes, '-x');
     }
     $zipFile = __DIR__ . '/../../../../../data/source.zip';
     if (file_exists($zipFile)) {
         unlink($zipFile);
     }
     $this->shell->exec('zip', array_merge(array('-r', $zipFile, './', '-i', '*.php'), $excludes));
     chdir($currentDir);
 }