|
1
|
|
|
<?php |
|
2
|
|
|
namespace NamespaceProtector; |
|
3
|
|
|
|
|
4
|
|
|
use NamespaceProtector\Analyser; |
|
5
|
|
|
use NamespaceProtector\Scanner\ComposerJson; |
|
6
|
|
|
use NamespaceProtector\Scanner\FileSystemScanner; |
|
7
|
|
|
|
|
8
|
|
|
class NamespaceProtectorProcessor |
|
9
|
|
|
{ |
|
10
|
|
|
private const NAMESPACE_PROTECTOR_CACHE = 'namespace-protector-cache'; |
|
11
|
|
|
|
|
12
|
|
|
private $config; |
|
|
|
|
|
|
13
|
|
|
private $composerJson; |
|
14
|
|
|
private $fileSystemScanner; |
|
15
|
|
|
private $analyser; |
|
16
|
|
|
private $environmentDataLoader; |
|
17
|
|
|
private $context = []; |
|
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
public function __construct( |
|
20
|
|
|
ComposerJson $composerJson, |
|
21
|
|
|
FileSystemScanner $fileSystemScanner, |
|
22
|
|
|
Analyser $analyser, |
|
23
|
|
|
EnvironmentDataLoader $environmentDataLoader |
|
24
|
|
|
) { |
|
25
|
|
|
$this->composerJson = $composerJson; |
|
26
|
|
|
$this->fileSystemScanner = $fileSystemScanner; |
|
27
|
|
|
$this->analyser = $analyser; |
|
28
|
|
|
$this->environmentDataLoader = $environmentDataLoader; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function load(): void |
|
32
|
|
|
{ |
|
33
|
|
|
$this->composerJson->load(); |
|
34
|
|
|
$this->fileSystemScanner->load(); |
|
35
|
|
|
$this->environmentDataLoader->load(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function getFilesLoaded(): int |
|
39
|
|
|
{ |
|
40
|
|
|
return \count($this->fileSystemScanner->getFileLoaded()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function getCountErrors(): int |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->analyser->getCountErrors(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function totalSymbolsLoaded(): int |
|
49
|
|
|
{ |
|
50
|
|
|
return |
|
51
|
|
|
($this->environmentDataLoader->getCollectBaseClasses()->count()) + |
|
52
|
|
|
($this->environmentDataLoader->getCollectBaseInterfaces()->count()) + |
|
53
|
|
|
($this->environmentDataLoader->getCollectBaseFunctions()->count()) + |
|
54
|
|
|
($this->environmentDataLoader->getCollectBaseConstants()->count()); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function process(): bool |
|
58
|
|
|
{ |
|
59
|
|
|
$this->processEntries($this->fileSystemScanner, $this->analyser); |
|
60
|
|
|
|
|
61
|
|
|
if ($this->analyser->withError()) { |
|
62
|
|
|
return false; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return true; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
private function processEntries(FileSystemScanner $fileSystemScanner, Analyser $analyser): void |
|
69
|
|
|
{ |
|
70
|
|
|
foreach ($fileSystemScanner->getFileLoaded() as $file) { |
|
71
|
|
|
$analyser->execute($file); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
} |
|
75
|
|
|
|