/**
* @param ContextInterface $context
* @return TaskResult
*/
public function run(ContextInterface $context)
{
$config = $this->getConfiguration();
$files = $context->getFiles()->extensions($config['triggered_by']);
if (0 === count($files)) {
return TaskResult::createSkipped($this, $context);
}
if (is_file('./vendor/bin/fixbom')) {
$fixCommand = './vendor/bin/fixbom';
} elseif (is_file('./bin/fixbom')) {
$fixCommand = './bin/fixbom';
} else {
$fixCommand = 'fixbom';
}
$shouldGetFixedLog = [];
/** @var \Symfony\Component\Finder\SplFileInfo $file */
foreach ($files as $file) {
$execFile = $file->getPathname();
$debugLog[] = $execFile;
if ($this->isFileWithBOM($execFile)) {
$shouldGetFixedLog[] = $execFile . " has BOM and should be fixed";
$fixCommand .= " '" . $execFile . "'";
}
}
if (count($shouldGetFixedLog) > 0) {
return TaskResult::createFailed($this, $context, implode(PHP_EOL, $shouldGetFixedLog) . PHP_EOL . "you can use this to fix them:" . PHP_EOL . $fixCommand);
}
return TaskResult::createPassed($this, $context);
}