Completed
Push — master ( 4da4bd...5ab290 )
by Scott
14s
created

PhpMndLoader::getErrorsOnLine()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 9
loc 9
rs 9.6666
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
    /**
16
     * @inheritdoc
17
     */
18
    public function parseLines()
19
    {
20
        while (($line = fgets($this->file)) !== false) {
21
            $matches = [];
22
            if (preg_match("/^(?<filename>[^:]+):(?<lineNo>[0-9]+)\. (?<message>.+)/", $line, $matches)) {
23
                $this->invalidLines
24
                    [$matches['filename']]
25
                    [$matches['lineNo']][] = $matches['message'];
26
            }
27
        }
28
29
        return array_keys($this->invalidLines);
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35 View Code Duplication
    public function getErrorsOnLine($file, $lineNumber)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37
        $errors = [];
38
        if (isset($this->invalidLines[$file][$lineNumber])) {
39
            $errors = $this->invalidLines[$file][$lineNumber];
40
        }
41
42
        return $errors;
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
    /**
54
     * {@inheritdoc}
55
     */
56
    public static function getDescription()
57
    {
58
        return 'Parses the text output of phpmnd (Magic Number Detection)';
59
    }
60
}
61