Ejemplo n.º 1
0
 /**
  * @param string $expected
  * @param string $arg
  *
  * @dataProvider casesEscapeShellArgWithWildcard
  *
  * @covers ::escapeShellArgWithWildcard
  */
 public function testEscapeShellArgWithWildcard($expected, $arg)
 {
     $this->tester->assertEquals($expected, Utils::escapeShellArgWithWildcard($arg));
 }
Ejemplo n.º 2
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);
 }