Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function runLint()
 {
     $reports = [];
     $files = $this->getJarValueOrLocal('files');
     $backupFailOn = $this->getFailOn();
     $this->setFailOn('never');
     foreach ($files as $fileName => $file) {
         if (!is_array($file)) {
             $file = ['fileName' => $fileName, 'content' => $file];
         }
         $this->currentFile = $file;
         $this->setStdinPath($fileName);
         $lintExitCode = $this->lintExitCode;
         parent::runLint();
         $this->lintExitCode = max($lintExitCode, $this->lintExitCode);
         if ($this->report) {
             $reports[] = $this->report;
         }
     }
     $this->setFailOn($backupFailOn);
     $this->report = Utils::mergeReports($reports);
     $this->reportRaw = json_encode($this->report);
     return $this;
 }
Example #2
0
 /**
  * @param string $expected
  * @param string $arg
  *
  * @dataProvider casesEscapeShellArgWithWildcard
  *
  * @covers ::escapeShellArgWithWildcard
  */
 public function testEscapeShellArgWithWildcard($expected, $arg)
 {
     $this->tester->assertEquals($expected, Utils::escapeShellArgWithWildcard($arg));
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function getCommand(array $options = null)
 {
     if ($options === null) {
         $options = $this->buildOptions();
     }
     $cmdPattern = '%s';
     $cmdArgs = [escapeshellcmd($this->phpcsExecutable)];
     foreach ($this->triStateOptions as $config => $option) {
         if (isset($options[$config])) {
             $cmdPattern .= $options[$config] ? " --{$option}" : " --no-{$option}";
         }
     }
     foreach ($this->simpleOptions as $config => $option) {
         if (isset($options[$config]) && ($options[$config] === 0 || $options[$config] === '0' || $options[$config])) {
             $cmdPattern .= " --{$option}=%s";
             $cmdArgs[] = escapeshellarg($options[$config]);
         }
     }
     foreach ($this->listOptions as $config => $option) {
         if (!empty($options[$config])) {
             $items = $this->filterEnabled($options[$config]);
             if ($items) {
                 $cmdPattern .= " --{$option}=%s";
                 $cmdArgs[] = escapeshellarg(implode(',', $items));
             }
         }
     }
     ksort($options['reports']);
     foreach ($options['reports'] as $reportType => $reportDst) {
         if ($reportDst === null) {
             $cmdPattern .= ' --report=%s';
             $cmdArgs[] = escapeshellarg($reportType);
         } elseif ($reportDst) {
             $cmdPattern .= ' --report-%s=%s';
             $cmdArgs[] = escapeshellarg($reportType);
             $cmdArgs[] = escapeshellarg($reportDst);
         }
     }
     if ($this->addFilesToCliCommand) {
         $files = $this->filterEnabled($this->getFiles());
         if ($files) {
             $cmdPattern .= ' --' . str_repeat(' %s', count($files));
             foreach ($files as $file) {
                 $cmdArgs[] = Utils::escapeShellArgWithWildcard($file);
             }
         }
     }
     return vsprintf($cmdPattern, $cmdArgs);
 }