ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
CSVFormatter.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 
27 class CSVFormatter implements ErrorFormatter
28 {
29  private const COMPONENT_REGEX = '/.*(Modules|Services|src)\/(.*?)\/.*/m';
30  private const H_COMPONENT = 'Component';
31  private const H_CLASS = 'Filename';
32  private const H_LINE = 'Line';
33  private const H_MESSAGE = 'Used Implementation';
34  private const UNKNOWN = 'Unknown';
35  private const H_RULE = 'Rule';
36  private const H_VERSION = 'Version';
37 
38  private array $csv_headers = [
39  self::H_COMPONENT,
40  self::H_CLASS,
41  self::H_VERSION,
42  self::H_LINE,
43  self::H_RULE,
44  self::H_MESSAGE
45  ];
46 
47 
48  public function formatErrors(AnalysisResult $analysisResult, Output $output): int
49  {
50  $getcwd = getcwd();
51  $output->writeLineFormatted(implode(';', $this->csv_headers));
52 
53  foreach ($analysisResult->getFileSpecificErrors() as $fileSpecificError) {
54  $filename = str_replace($getcwd, '', $fileSpecificError->getFile());
55  if (preg_match(self::COMPONENT_REGEX, $filename, $matches)) {
56  $component = $matches[1] . '/' . $matches[2];
57  } else {
58  $component = self::UNKNOWN;
59  }
60 
61  $result = [
62  self::H_COMPONENT => $component,
63  self::H_CLASS => basename($fileSpecificError->getFile()),
64  self::H_VERSION => $fileSpecificError->getMetadata()['version'] ?? self::UNKNOWN,
65  self::H_LINE => $fileSpecificError->getLine(),
66  self::H_RULE => $fileSpecificError->getMetadata()['rule'] ?? self::UNKNOWN,
67  self::H_MESSAGE => $fileSpecificError->getMessage()
68  ];
69  $output->writeLineFormatted(implode(';', $result));
70  }
71  return $analysisResult->hasErrors() ? 1 : 0;
72  }
73 }
$result
$filename
Definition: buildRTE.php:89
formatErrors(AnalysisResult $analysisResult, Output $output)