-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathGraphApplication.php
More file actions
57 lines (47 loc) · 1.37 KB
/
GraphApplication.php
File metadata and controls
57 lines (47 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace staabm\PHPStanBaselineAnalysis;
use \Iterator;
final class GraphApplication
{
/**
* @api
*/
public function start(string $jsonGlob): int
{
$jsonFiles = glob($jsonGlob, GLOB_NOSORT) ?: [];
usort( $jsonFiles, function( string $a, string $b ) {
return filemtime($a) - filemtime($b);
});
if (!$jsonFiles) {
throw new \RuntimeException('No files found for ' . $jsonGlob);
}
$it = $this->iterateOverFiles($jsonFiles);
$graph = new GraphTemplate();
echo $graph->render($it);
return 0;
}
/**
* @api
*/
public function help(): void
{
printf("USAGE: phpstan-baseline-graph '<glob-pattern>'");
}
/**
* @param list<string> $jsonFiles
* @return Iterator<array{string, AnalyzerResult}>
*/
private function iterateOverFiles(array $jsonFiles): Iterator
{
$reader = new AnalyzerResultReader();
foreach ($jsonFiles as $jsonFile) {
if (strpos($jsonFile, '.json') === false) {
throw new \RuntimeException('Expecting json file, got ' . $jsonFile);
}
$results = $reader->readFile($jsonFile);
foreach ($results as $baselinePath => $analyzerResult) {
yield [$baselinePath, $analyzerResult];
}
}
}
}