/** * Writes a report in checkstyle XML format. * * @param \Helmich\TypoScriptLint\Linter\Report\Report $report The report to print. * @return void */ public function writeReport(Report $report) { $xml = new \DOMDocument('1.0', 'UTF-8'); $root = $xml->createElement('checkstyle'); $root->setAttribute('version', APP_NAME . '-' . APP_VERSION); foreach ($report->getFiles() as $file) { $xmlFile = $xml->createElement('file'); $xmlFile->setAttribute('name', $file->getFilename()); foreach ($file->getWarnings() as $warning) { $xmlWarning = $xml->createElement('error'); $xmlWarning->setAttribute('line', $warning->getLine()); $xmlWarning->setAttribute('severity', $warning->getSeverity()); $xmlWarning->setAttribute('message', $warning->getMessage()); $xmlWarning->setAttribute('source', $warning->getSource()); if ($warning->getColumn() !== NULL) { $xmlWarning->setAttribute('column', $warning->getColumn()); } $xmlFile->appendChild($xmlWarning); } $root->appendChild($xmlFile); } $xml->appendChild($root); $xml->formatOutput = TRUE; $this->output->write($xml->saveXML()); }
/** * @medium */ public function testPlaintextReportIsCorrectlyGenerated() { $file1 = new File('foobar.tys'); $file1->addWarning(new Warning(123, 12, 'Message #1', Warning::SEVERITY_INFO, 'foobar')); $file1->addWarning(new Warning(124, NULL, 'Message #2', Warning::SEVERITY_WARNING, 'foobar')); $file2 = new File('bar.txt'); $file2->addWarning(new Warning(412, 141, 'Message #3', Warning::SEVERITY_ERROR, 'barbaz')); $report = new Report(); $report->addFile($file1); $report->addFile($file2); $this->printer->writeReport($report); $this->assertEquals(self::EXPECTED_XML_DOCUMENT, $this->output->fetch()); }
/** * @medium */ public function testXmlReportIsCorrectlyGenerated() { $file1 = new File('foobar.tys'); $file1->addWarning(new Warning(123, 12, 'Message #1', Warning::SEVERITY_INFO, 'foobar')); $file1->addWarning(new Warning(124, NULL, 'Message #2', Warning::SEVERITY_WARNING, 'foobar')); $file2 = new File('bar.txt'); $file2->addWarning(new Warning(412, 141, 'Message #3', Warning::SEVERITY_ERROR, 'barbaz')); $report = new Report(); $report->addFile($file1); $report->addFile($file2); $this->output->expects($this->once())->method('write')->with(self::EXPECTED_XML_DOCUMENT); $this->printer->writeReport($report); }
/** * @param string $filename * @param \Helmich\TypoScriptLint\Linter\Report\Report $report * @param \Helmich\TypoScriptLint\Linter\LinterConfiguration $configuration * @param \Symfony\Component\Console\Output\OutputInterface $output */ public function lintFile($filename, Report $report, LinterConfiguration $configuration, OutputInterface $output) { $file = new File($filename); try { $tokens = $this->tokenizer->tokenizeStream($filename); $statements = $this->parser->parseTokens($tokens); $this->lintTokenStream($tokens, $file, $configuration, $output); $this->lintSyntaxTree($statements, $file, $configuration, $output); } catch (TokenizerException $tokenizerException) { $file->addWarning(Warning::createFromTokenizerError($tokenizerException)); } catch (ParseError $parseError) { $file->addWarning(Warning::createFromParseError($parseError)); } if (count($file->getWarnings()) > 0) { $report->addFile($file); } }
/** * Writes a report in human-readable table form. * * @param \Helmich\TypoScriptLint\Linter\Report\Report $report The report to print. * @return void */ public function writeReport(Report $report) { $count = 0; $this->output->writeln(''); $this->output->writeln('<comment>CHECKSTYLE REPORT</comment>'); $styleMap = [Warning::SEVERITY_ERROR => 'error', Warning::SEVERITY_WARNING => 'comment', Warning::SEVERITY_INFO => 'info']; foreach ($report->getFiles() as $file) { $this->output->writeln("=> <comment>{$file->getFilename()}</comment>."); foreach ($file->getWarnings() as $warning) { $count++; $style = $styleMap[$warning->getSeverity()]; $this->output->writeln(sprintf('<comment>%4d <%s>%s</%s></comment>', $warning->getLine(), $style, $warning->getMessage(), $style)); } } $this->output->writeln(""); $this->output->writeln('<comment>SUMMARY</comment>'); $this->output->writeln("<info><comment>{$count}</comment> warnings in total.</info>"); }