1 | <?php |
||
2 | namespace exussum12\CoverageChecker\Loaders; |
||
3 | |||
4 | use exussum12\CoverageChecker\FileChecker; |
||
5 | |||
6 | class PhpMnd implements FileChecker |
||
7 | { |
||
8 | private $invalidLines = []; |
||
9 | |||
10 | private $file; |
||
11 | |||
12 | public function __construct($filename) |
||
13 | { |
||
14 | $this->file = fopen($filename, 'r'); |
||
15 | } |
||
16 | |||
17 | /** |
||
18 | * @inheritdoc |
||
19 | */ |
||
20 | public function parseLines(): array |
||
21 | { |
||
22 | while (($line = fgets($this->file)) !== false) { |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
23 | $matches = []; |
||
24 | $pattern = "/^(?<filename>[^:]+):(?<lineNo>[0-9]+)\. (?<message>.+)/"; |
||
25 | if (preg_match($pattern, $line, $matches)) { |
||
26 | $this->invalidLines |
||
27 | [$matches['filename']] |
||
28 | [$matches['lineNo']][] = $matches['message']; |
||
29 | } |
||
30 | } |
||
31 | |||
32 | return array_keys($this->invalidLines); |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * @inheritdoc |
||
37 | */ |
||
38 | public function getErrorsOnLine(string $file, int $lineNumber) |
||
39 | { |
||
40 | $errors = []; |
||
41 | if (isset($this->invalidLines[$file][$lineNumber])) { |
||
42 | $errors = $this->invalidLines[$file][$lineNumber]; |
||
43 | } |
||
44 | |||
45 | return $errors; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * return as true to include files, phpmnd only shows files with errors |
||
50 | */ |
||
51 | public function handleNotFoundFile() |
||
52 | { |
||
53 | return true; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | public static function getDescription(): string |
||
60 | { |
||
61 | return 'Parses the text output of phpmnd (Magic Number Detection)'; |
||
62 | } |
||
63 | } |
||
64 |