Completed
Push — master ( bd7133...e05a5e )
by BruceScrutinizer
07:36
created

NamespaceProtectorProcessor   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 28
dl 0
loc 64
rs 10
c 1
b 0
f 0
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilesLoaded() 0 3 1
A load() 0 5 1
A __construct() 0 10 1
A processEntries() 0 4 2
A totalSymbolsLoaded() 0 7 1
A process() 0 9 2
A getCountErrors() 0 3 1
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;
0 ignored issues
show
introduced by
The private property $config is not used, and could be removed.
Loading history...
13
    private $composerJson;
14
    private $fileSystemScanner;
15
    private $analyser;
16
    private $environmentDataLoader;
17
    private $context = [];
0 ignored issues
show
introduced by
The private property $context is not used, and could be removed.
Loading history...
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