Passed
Push — master ( 31de2d...8df2bc )
by Scott
33s
created

PhpMndLoader::isValidLine()   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 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
namespace exussum12\CoverageChecker;
3
4
use XMLReader;
5
6
class PhpMndLoader 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
     * @return array array containing filename and line numbers
18
     */
19
    public function getLines()
20
    {
21
        while (($line = fgets($this->file)) !== false) {
22
            $matches = [];
23
            if (preg_match("/^(?<filename>[^:]+):(?<lineNo>[0-9]+)\. (?<message>.+)/", $line, $matches)) {
24
                $this->invalidLines
25
                    [$matches['filename']]
26
                    [$matches['lineNo']] = $matches['message'];
27
            }
28
        }
29
30
        return $this->invalidLines;
31
    }
32
33
    /**
34
     * Method to determine if the line is valid in the context
35
     * null does not include the line in the stats
36
     * @param $file
37
     * @param $lineNumber
38
     * @return bool|null
39
     */
40
    public function isValidLine($file, $lineNumber)
41
    {
42
        return empty($this->invalidLines[$file][$lineNumber]);
43
    }
44
45
    /**
46
     * return as true to include files, phpmnd only shows files with errors
47
     */
48
    public function handleNotFoundFile()
49
    {
50
        return true;
51
    }
52
}
53