|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the reliforp/reli-prof package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) sji <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Reli\Converter; |
|
15
|
|
|
|
|
16
|
|
|
use PhpCast\Cast; |
|
|
|
|
|
|
17
|
|
|
use Webmozart\Assert\Assert; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
final class PhpSpyCompatibleParser |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @param resource $fp |
|
23
|
|
|
* @return iterable<ParsedCallTrace> |
|
24
|
|
|
*/ |
|
25
|
|
|
public function parseFile($fp): iterable |
|
26
|
|
|
{ |
|
27
|
|
|
$buffer = []; |
|
28
|
|
|
while (($line = fgets($fp)) !== false) { |
|
29
|
|
|
$line = trim($line); |
|
30
|
|
|
if ($line !== '') { |
|
31
|
|
|
$buffer[] = $line; |
|
32
|
|
|
continue; |
|
33
|
|
|
} |
|
34
|
|
|
yield $this->parsePhpSpyCompatible($buffer); |
|
35
|
|
|
$buffer = []; |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** @param string[] $buffer */ |
|
40
|
|
|
private function parsePhpSpyCompatible(array $buffer): ParsedCallTrace |
|
41
|
|
|
{ |
|
42
|
|
|
$frames = []; |
|
43
|
|
|
foreach ($buffer as $line_buffer) { |
|
44
|
|
|
$result = explode(' ', $line_buffer); |
|
45
|
|
|
[$depth, $name, $file_line] = $result; |
|
46
|
|
|
if ($depth === '#') { // comment |
|
47
|
|
|
continue; |
|
48
|
|
|
} |
|
49
|
|
|
Assert::stringNotEmpty($file_line); |
|
50
|
|
|
[$file, $line] = $this->splitLineNumberAndFilePath($file_line); |
|
51
|
|
|
$frames[] = new ParsedCallFrame( |
|
52
|
|
|
$name, |
|
53
|
|
|
$file, |
|
54
|
|
|
$line, |
|
55
|
|
|
); |
|
56
|
|
|
} |
|
57
|
|
|
return new ParsedCallTrace(...$frames); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @param non-empty-string $file_line |
|
|
|
|
|
|
62
|
|
|
* @return array{non-empty-string, int} |
|
|
|
|
|
|
63
|
|
|
*/ |
|
64
|
|
|
private function splitLineNumberAndFilePath(string $file_line): array |
|
65
|
|
|
{ |
|
66
|
|
|
$separator_position = strrpos($file_line, ':'); |
|
67
|
|
|
Assert::notFalse($separator_position); |
|
68
|
|
|
$line = substr($file_line, $separator_position + 1); |
|
69
|
|
|
$file = substr($file_line, 0, $separator_position); |
|
70
|
|
|
Assert::stringNotEmpty($file); |
|
71
|
|
|
return [$file, Cast::toInt($line)]; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths