|
1
|
|
|
<?php |
|
2
|
|
|
namespace exussum12\CoverageChecker; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* Class PhpStanLoader |
|
6
|
|
|
* Used for parsing phpstan standard output |
|
7
|
|
|
* @package exussum12\CoverageChecker |
|
8
|
|
|
*/ |
|
9
|
|
|
class PhpStanLoader implements FileChecker |
|
10
|
|
|
{ |
|
11
|
|
|
protected $lineRegex = '/^\s+(?<lineNumber>[0-9]+)/'; |
|
12
|
|
|
/** |
|
13
|
|
|
* @var string |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $file; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var array |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $errors = []; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var array |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $errorRanges = []; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param string $filename the path to the phpstan.txt file |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct($filename) |
|
31
|
|
|
{ |
|
32
|
|
|
$this->file = fopen($filename, 'r'); |
|
|
|
|
|
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* {@inheritdoc} |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getLines() |
|
39
|
|
|
{ |
|
40
|
|
|
$filename = ''; |
|
41
|
|
|
while (($line = fgets($this->file)) !== false) { |
|
42
|
|
|
$filename = $this->checkForFileName($line, $filename); |
|
43
|
|
|
if ($lineNumber = $this->getLineNumber($line)) { |
|
44
|
|
|
$this->invalidLines |
|
|
|
|
|
|
45
|
|
|
[$filename] |
|
46
|
|
|
[$lineNumber] = $this->getMessage($line); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return $this->invalidLines; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* {@inheritdoc} |
|
55
|
|
|
*/ |
|
56
|
|
|
public function isValidLine($file, $lineNumber) |
|
57
|
|
|
{ |
|
58
|
|
|
return empty($this->isValidLines[$file][$lineNumber]); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* {@inheritdoc} |
|
64
|
|
|
*/ |
|
65
|
|
|
public function handleNotFoundFile() |
|
66
|
|
|
{ |
|
67
|
|
|
return null; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @param string $line |
|
72
|
|
|
* @param string $currentFile |
|
73
|
|
|
* @return string the currentFileName |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function checkForFilename($line, $currentFile) |
|
76
|
|
|
{ |
|
77
|
|
|
if (strpos($line, " Line ")) { |
|
78
|
|
|
return trim(str_replace('Line', '',$line)); |
|
79
|
|
|
} |
|
80
|
|
|
return $currentFile; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
protected function getLineNumber($line) |
|
84
|
|
|
{ |
|
85
|
|
|
$matches = []; |
|
86
|
|
|
if (!preg_match('' . $this->lineRegex, $line, $matches)) { |
|
87
|
|
|
return false; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
return $matches['lineNumber']; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
protected function getMessage($line) |
|
94
|
|
|
{ |
|
95
|
|
|
return trim(preg_replace($this->lineRegex, "", $line)); |
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..