/**
* {@inheritdoc}
*/
public function run(ContextInterface $context)
{
/** @var array $config */
$config = $this->getConfiguration();
/** @var array $whitelistPatterns */
$whitelistPatterns = $config['whitelist_patterns'];
/** @var array $extensions */
$extensions = $config['triggered_by'];
/** @var \GrumPHP\Collection\FilesCollection $files */
$files = $context->getFiles();
if (0 !== count($whitelistPatterns)) {
$files = $files->paths($whitelistPatterns);
}
$files = $files->extensions($extensions);
if (0 === count($files)) {
return TaskResult::createSkipped($this, $context);
}
$arguments = $this->processBuilder->createArgumentsForCommand('phpcs');
$arguments = $this->addArgumentsFromConfig($arguments, $config);
$arguments->add('--report-full');
$arguments->add('--report-json');
$arguments->addFiles($files);
$process = $this->processBuilder->buildProcess($arguments);
$process->run();
if (!$process->isSuccessful()) {
$output = $this->formatter->format($process);
try {
$arguments = $this->processBuilder->createArgumentsForCommand('phpcbf');
$arguments = $this->addArgumentsFromConfig($arguments, $config);
$output .= $this->formatter->formatErrorMessage($arguments, $this->processBuilder);
} catch (RuntimeException $exception) {
// phpcbf could not get found.
$output .= PHP_EOL . 'Info: phpcbf could not get found. Please consider to install it for suggestions.';
}
return TaskResult::createFailed($this, $context, $output);
}
return TaskResult::createPassed($this, $context);
}