/** * @inheritdoc */ public function process(File $file, Report $report) { $cmd = sprintf('php --syntax-check %s', $file->getPath()); $process = new Process($cmd); $process->run(); # Create the array of outputs and remove empty values. $output = array_filter(explode(PHP_EOL, $process->getOutput())); if ($process->isSuccessful()) { return; } $regex = '!\\s+on line (\\d+)!'; $needle = 'Parse error: syntax error, '; foreach (array_slice($output, 0, count($output) - 1) as $error) { $raw = ucfirst(substr($error, strlen($needle))); $message = str_replace(' in ' . $file->getPath(), '', $raw); $line = 0; preg_match($regex, $message, $lineMatch); if (isset($lineMatch[1])) { $line = (int) $lineMatch[1]; $message = preg_replace($regex, '', $message); } $report->addMessage($file, $this, $message, $line); } }
/** * @inheritdoc */ public function process(File $file, Report $report) { $process = new Process(sprintf('composer validate %s', $file->getPath())); $process->run(); if ($process->isSuccessful()) { return; } $errorOutput = $process->getErrorOutput(); preg_match('!Parse error on line (\\d+):!', $errorOutput, $matchedLine); $line = 1; if (isset($matchedLine[1])) { $line = (int) $matchedLine[1]; } $report->addMessage($file, $this, 'Invalid composer.json file format', $line); }