PhpMnd::parseLines()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 0
dl 0
loc 13
rs 10
c 0
b 0
f 0
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
It seems like $this->file can also be of type boolean; however, parameter $handle of fgets() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

22
        while (($line = fgets(/** @scrutinizer ignore-type */ $this->file)) !== false) {
Loading history...
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