1 | <?php |
||
9 | class AnalysisResult |
||
10 | { |
||
11 | /** |
||
12 | * Result data. |
||
13 | * @var array analysis result data. |
||
14 | */ |
||
15 | protected $data = []; |
||
16 | |||
17 | /** |
||
18 | * Analysis result filter. |
||
19 | * @var OutputFilterInterface filter instance. |
||
20 | */ |
||
21 | protected $filter; |
||
22 | |||
23 | /** |
||
24 | * Register an issue. |
||
25 | * @param string $fileName File name. |
||
26 | * @param integer $line Line number. |
||
27 | * @param string $toolName Analysis tool name. |
||
28 | * @param string $issueType Issue type. |
||
29 | * @param string $message Issue description. |
||
30 | * @return void |
||
31 | */ |
||
32 | public function addIssue($fileName, $line, $toolName, $issueType, $message) |
||
33 | { |
||
34 | if (!isset($this->data[$fileName])) { |
||
35 | $this->data[$fileName] = []; |
||
36 | } |
||
37 | |||
38 | if (!isset($this->data[$fileName][$line])) { |
||
39 | $this->data[$fileName][$line] = []; |
||
40 | } |
||
41 | |||
42 | $this->data[$fileName][$line][] = [ |
||
43 | 'tool' => $toolName, |
||
44 | 'type' => $issueType, |
||
45 | 'message' => $message, |
||
46 | ]; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Check if there are any code issues. |
||
51 | * @return boolean true if there are issues. |
||
52 | */ |
||
53 | public function hasIssues() |
||
59 | |||
60 | /** |
||
61 | * Return result data as an array. |
||
62 | * <code> |
||
63 | * file_name => [ |
||
64 | * line_number => [ |
||
65 | * issue 1, |
||
66 | * issue 2, |
||
67 | * ... |
||
68 | * ] |
||
69 | * ] |
||
70 | * </code> |
||
71 | * @return array result daya. |
||
72 | */ |
||
73 | public function toArray() |
||
74 | { |
||
75 | $data = []; |
||
76 | |||
77 | foreach ($this->data as $fileName => $lines) { |
||
78 | ksort($lines); |
||
79 | $data[$fileName] = $lines; |
||
80 | } |
||
81 | |||
82 | ksort($data); |
||
83 | |||
84 | if (null !== $this->filter) { |
||
85 | $data = $this->filter->filter($data); |
||
86 | } |
||
87 | |||
88 | return $data; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Merge the data of another result into this one. |
||
93 | * @param AnalysisResult $other another analysis result object. |
||
94 | * @return AnalysisResult returns itself. |
||
95 | */ |
||
96 | public function mergeWith(AnalysisResult $other) |
||
113 | |||
114 | /** |
||
115 | * Add an output filter to delegate to the analysis result object. |
||
116 | * @param OutputFilterInterface $filter filter instance. |
||
117 | */ |
||
118 | public function setResultsFilter(OutputFilterInterface $filter) |
||
122 | } |
||
123 |