1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace NamespaceProtector; |
4
|
|
|
|
5
|
|
|
use NamespaceProtector\Config\Config; |
6
|
|
|
use NamespaceProtector\Scanner\ComposerJson; |
7
|
|
|
use NamespaceProtector\Result\ResultAnalyser; |
8
|
|
|
use NamespaceProtector\Result\ResultProcessor; |
9
|
|
|
use NamespaceProtector\Scanner\FileSystemScanner; |
10
|
|
|
use NamespaceProtector\Result\ResultAnalyserInterface; |
11
|
|
|
use NamespaceProtector\Result\ResultCollector; |
12
|
|
|
use NamespaceProtector\Result\ResultCollectorReadable; |
13
|
|
|
use NamespaceProtector\Result\ResultProcessorInterface; |
14
|
|
|
|
15
|
|
|
final class NamespaceProtectorProcessor |
16
|
|
|
{ |
17
|
|
|
/** @var Config */ |
18
|
|
|
private $config; |
|
|
|
|
19
|
|
|
|
20
|
|
|
/** @var ComposerJson */ |
21
|
|
|
private $composerJson; |
22
|
|
|
|
23
|
|
|
/** @var FileSystemScanner */ |
24
|
|
|
private $fileSystemScanner; |
25
|
|
|
|
26
|
|
|
/** @var Analyser */ |
27
|
|
|
private $analyser; |
28
|
|
|
|
29
|
|
|
/** @var EnvironmentDataLoaderInterface */ |
30
|
|
|
private $environmentDataLoader; |
31
|
|
|
|
32
|
|
|
public function __construct( |
33
|
|
|
ComposerJson $composerJson, |
34
|
|
|
FileSystemScanner $fileSystemScanner, |
35
|
|
|
Analyser $analyser, |
36
|
|
|
EnvironmentDataLoader $environmentDataLoader |
37
|
|
|
) { |
38
|
|
|
$this->composerJson = $composerJson; |
39
|
|
|
$this->fileSystemScanner = $fileSystemScanner; |
40
|
|
|
$this->analyser = $analyser; |
41
|
|
|
$this->environmentDataLoader = $environmentDataLoader; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function load(): void |
45
|
|
|
{ |
46
|
|
|
$this->composerJson->load(); |
47
|
|
|
$this->fileSystemScanner->load(); |
48
|
|
|
$this->environmentDataLoader->load(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function getFilesLoaded(): int |
52
|
|
|
{ |
53
|
|
|
return \count($this->fileSystemScanner->getFileLoaded()); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function totalSymbolsLoaded(): int |
57
|
|
|
{ |
58
|
|
|
return |
59
|
|
|
($this->environmentDataLoader->getCollectBaseClasses()->count()) + |
60
|
|
|
($this->environmentDataLoader->getCollectBaseInterfaces()->count()) + |
61
|
|
|
($this->environmentDataLoader->getCollectBaseFunctions()->count()) + |
62
|
|
|
($this->environmentDataLoader->getCollectBaseConstants()->count()); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function process(): ResultProcessorInterface |
66
|
|
|
{ |
67
|
|
|
/** @var ResultAnalyser $result */ |
68
|
|
|
$result = $this->processEntries($this->fileSystemScanner, $this->analyser); |
69
|
|
|
if ($result->withResults()) { |
70
|
|
|
return new ResultProcessor( |
71
|
|
|
['<fg=red>Total errors: ' . $result->count() . '</>'], |
72
|
|
|
$result->getResultCollector() |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return new ResultProcessor(['<fg=blue>No output</>'], $result->getResultCollector()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
private function processEntries(FileSystemScanner $fileSystemScanner, Analyser $analyser): ResultAnalyserInterface |
80
|
|
|
{ |
81
|
|
|
/** @var ResultAnalyserInterface */ |
82
|
|
|
$totalResult = new ResultAnalyser(new ResultCollectorReadable(new ResultCollector())); |
83
|
|
|
|
84
|
|
|
foreach ($fileSystemScanner->getFileLoaded() as $file) { |
85
|
|
|
$currentResult = $analyser->execute($file); |
86
|
|
|
$totalResult = $totalResult->append($currentResult); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return $totalResult; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|