Repository navigation
Expand file tree
/
Copy pathAnalysedTemplatesRegistry.php
More file actions
108 lines (94 loc) · 2.67 KB
/
Copy pathAnalysedTemplatesRegistry.php
File metadata and controls
108 lines (94 loc) · 2.67 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
declare(strict_types=1);
namespace Efabrica\PHPStanLatte\Analyser;
use Nette\Utils\Finder;
use PHPStan\File\FileExcluder;
use SplFileInfo;
use function array_filter;
use function array_keys;
use function array_unique;
use function is_dir;
use function realpath;
use function sort;
final class AnalysedTemplatesRegistry
{
private FileExcluder $fileExcluder;
/** @var string[] */
private array $analysedPaths = [];
private bool $reportUnanalysedTemplates;
/** @var array<string, bool> */
private array $templateFiles = [];
/**
* @param string[] $analysedPaths
*/
public function __construct(FileExcluder $fileExcluder, array $analysedPaths, bool $reportUnanalysedTemplates)
{
$this->fileExcluder = $fileExcluder;
$this->analysedPaths = $analysedPaths;
$this->reportUnanalysedTemplates = $reportUnanalysedTemplates;
foreach ($this->getExistingTemplates() as $file) {
$this->templateFiles[$file] = false;
}
}
public function isExcludedFromAnalysing(string $path): bool
{
return $this->fileExcluder->isExcludedFromAnalysing($path);
}
public function templateAnalysed(string $path): void
{
$path = realpath($path) ?: $path;
$this->templateFiles[$path] = true;
}
/**
* @return string[]
*/
public function getExistingTemplates(): array
{
$files = [];
foreach ($this->analysedPaths as $analysedPath) {
if (!is_dir($analysedPath)) {
continue;
}
/** @var SplFileInfo $file */
foreach (Finder::findFiles('*.latte')->from($analysedPath) as $file) {
$filePath = (string)$file;
if ($this->isExcludedFromAnalysing($filePath)) {
continue;
}
$files[] = $filePath;
}
}
$files = array_unique($files);
sort($files);
return $files;
}
/**
* @return string[]
*/
public function getAnalysedTemplates(): array
{
return array_keys(array_filter($this->templateFiles, function (bool $val) {
return $val;
}));
}
/**
* @return string[]
*/
public function getUnanalysedTemplates(): array
{
return array_keys(array_filter($this->templateFiles, function (bool $val) {
return !$val;
}));
}
/**
* @return string[]
*/
public function getReportedUnanalysedTemplates(): array
{
if ($this->reportUnanalysedTemplates) {
return $this->getUnanalysedTemplates();
} else {
return [];
}
}
}