Total Complexity | 10 |
Total Lines | 74 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
11 | abstract class Generic implements FileChecker |
||
12 | { |
||
13 | protected $lineMatch = ''; |
||
14 | |||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $file; |
||
19 | |||
20 | /** |
||
21 | * @var array |
||
22 | */ |
||
23 | protected $errors = []; |
||
24 | |||
25 | /** |
||
26 | * PhanJsonLoader constructor. |
||
27 | * @param string $file the path to the file containing phan output |
||
28 | */ |
||
29 | public function __construct($file) |
||
30 | { |
||
31 | $this->file = $file; |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | public function parseLines(): array |
||
38 | { |
||
39 | $handle = fopen($this->file, 'r'); |
||
40 | while (($line = fgets($handle)) !== false) { |
||
|
|||
41 | if (!$this->checkForFile($line)) { |
||
42 | continue; |
||
43 | } |
||
44 | |||
45 | $this->addError($line); |
||
46 | } |
||
47 | |||
48 | return array_keys($this->errors); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | public function getErrorsOnLine(string $file, int $lineNumber) |
||
55 | { |
||
56 | $errors = []; |
||
57 | if (isset($this->errors[$file][$lineNumber])) { |
||
58 | $errors = $this->errors[$file][$lineNumber]; |
||
59 | } |
||
60 | |||
61 | return $errors; |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | public function handleNotFoundFile() |
||
68 | { |
||
69 | return true; |
||
70 | } |
||
71 | |||
72 | |||
73 | private function checkForFile(string $line) |
||
74 | { |
||
75 | return preg_match($this->lineMatch, $line); |
||
76 | } |
||
77 | |||
78 | private function addError(string $line) |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 |