public static forExecutable ( string $executable ) : |
||
$executable | string | |
Résultat |
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $files = $context->getFiles()->name('*.php'); if (0 === count($files)) { return; } $config = $this->getConfiguration(); $arguments = ProcessArgumentsCollection::forExecutable($this->getCommandLocation()); $arguments->addOptionalArgument('--configuration=%s', $config['config_file']); $this->processBuilder->setArguments($arguments->getValues()); $process = $this->processBuilder->getProcess(); $process->run(); if (!$process->isSuccessful()) { throw new RuntimeException($process->getOutput()); } }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $files = $context->getFiles()->name('*.php'); if (0 === count($files)) { return; } $config = $this->getConfiguration(); $arguments = ProcessArgumentsCollection::forExecutable($this->getCommandLocation()); $arguments->add('--format=json'); $arguments->add('--dry-run'); $arguments->addOptionalArgument('--level=%s', $config['level']); $arguments->addOptionalArgument('--config=%s', $config['config']); $arguments->addOptionalArgument('--config-file=%s', $config['config_file']); $arguments->addOptionalArgument('--verbose', $config['verbose']); $arguments->addOptionalCommaSeparatedArgument('--fixers=%s', $config['fixers']); $arguments->add('fix'); $this->processBuilder->setArguments($arguments->getValues()); $messages = array(); $suggest = array('You can fix all errors by running following commands:'); $errorCount = 0; foreach ($files as $file) { $processBuilder = clone $this->processBuilder; $processBuilder->setArguments($arguments->getValues()); $processBuilder->add($file); $process = $processBuilder->getProcess(); $process->run(); if (!$process->isSuccessful()) { $output = $process->getOutput(); $json = json_decode($output, true); if ($json) { if (isset($json['files'][0]['name']) && isset($json['files'][0]['appliedFixers'])) { $messages[] = sprintf('%s) %s (%s)', ++$errorCount, $json['files'][0]['name'], implode(',', $json['files'][0]['appliedFixers'])); } elseif (isset($json['files'][0]['name'])) { $messages[] = sprintf('%s) %s', ++$errorCount, $json['files'][0]['name']); } $suggest[] = str_replace(array("'--dry-run' ", "'--format=json' "), '', $process->getCommandLine()); } else { $messages[] = $output; } } } if (count($messages)) { throw new RuntimeException(implode("\n", $messages) . "\n" . "\n" . implode("\n", $suggest)); } }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $files = $context->getFiles()->name('*.php'); if (0 === count($files)) { return; } $config = $this->getConfiguration(); $arguments = ProcessArgumentsCollection::forExecutable($this->getCommandLocation()); $arguments->addRequiredArgument('--standard=%s', $config['standard']); $arguments->addOptionalArgument('--warning-severity=0', !$config['show_warnings']); $arguments->addOptionalArgument('--tab-width=%s', $config['tab_width']); $arguments->addOptionalCommaSeparatedArgument('--sniffs=%s', $config['sniffs']); $arguments->addOptionalCommaSeparatedArgument('--ignore=%s', $config['ignore_patterns']); $arguments->addFiles($files); $this->processBuilder->setArguments($arguments->getValues()); $process = $this->processBuilder->getProcess(); $process->run(); if (!$process->isSuccessful()) { throw new RuntimeException($process->getOutput()); } }
/** * {@inheritdoc} */ public function run(ContextInterface $context) { $files = $context->getFiles()->name('*.php'); if (0 === count($files)) { return; } $config = $this->getConfiguration(); if (empty($config['keywords'])) { return; } $arguments = ProcessArgumentsCollection::forExecutable($this->getCommandLocation()); $arguments->add('grep'); $arguments->add('--cached'); $arguments->add('-n'); $arguments->addArgumentArray('-e %s', $config['keywords']); $arguments->addFiles($files); $this->processBuilder->setArguments($arguments->getValues()); $process = $this->processBuilder->getProcess(); $process->run(); if ($process->isSuccessful()) { throw new RuntimeException(sprintf("You have blacklisted keywords in your commit:\n%s", $process->getOutput())); } }
/** * @param string $command * * @return ProcessArgumentsCollection */ public function createArgumentsForCommand($command) { $executable = $this->getCommandLocation($command); return ProcessArgumentsCollection::forExecutable($executable); }