Completed
Push — master ( 7f5a29...8ce298 )
by Scott
13s
created

PhpMndLoader::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace exussum12\CoverageChecker;
3
4
class PhpMndLoader implements FileChecker
5
{
6
    private $invalidLines = [];
7
8
    private $file;
9
10
    public function __construct($filename)
11
    {
12
        $this->file = fopen($filename, 'r');
13
    }
14
    /**
15
     * @return array array containing filename and line numbers
16
     */
17
    public function getLines()
18
    {
19
        while (($line = fgets($this->file)) !== false) {
20
            $matches = [];
21
            if (preg_match("/^(?<filename>[^:]+):(?<lineNo>[0-9]+)\. (?<message>.+)/", $line, $matches)) {
22
                $this->invalidLines
23
                    [$matches['filename']]
24
                    [$matches['lineNo']] = $matches['message'];
25
            }
26
        }
27
28
        return $this->invalidLines;
29
    }
30
31
    /**
32
     * Method to determine if the line is valid in the context
33
     * null does not include the line in the stats
34
     * @param $file
35
     * @param $lineNumber
36
     * @return bool|null
37
     */
38
    public function isValidLine($file, $lineNumber)
39
    {
40
        return empty($this->invalidLines[$file][$lineNumber]);
41
    }
42
43
    /**
44
     * return as true to include files, phpmnd only shows files with errors
45
     */
46
    public function handleNotFoundFile()
47
    {
48
        return true;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public static function getDescription()
55
    {
56
        return 'Parses the text output of phpmnd';
57
    }
58
}
59