1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace NamespaceProtector\Parser\Node; |
6
|
|
|
|
7
|
|
|
use NamespaceProtector\Entry\Entry; |
8
|
|
|
use NamespaceProtector\Config\Config; |
9
|
|
|
use NamespaceProtector\Rule\FalsePositive; |
10
|
|
|
use NamespaceProtector\Rule\IsWithPrivateNamespace; |
11
|
|
|
use NamespaceProtector\EnvironmentDataLoaderInterface; |
12
|
|
|
use NamespaceProtector\Rule\IsInConfigureComposerPsr4; |
13
|
|
|
use NamespaceProtector\Rule\isInPrivateConfiguredEntries; |
14
|
|
|
use NamespaceProtector\Parser\Node\Event\EventProcessNodeInterface; |
15
|
|
|
|
16
|
|
|
final class ProcessUseStatement |
17
|
|
|
{ |
18
|
|
|
/** @var EnvironmentDataLoaderInterface */ |
19
|
|
|
private $metadataLoader; |
20
|
|
|
|
21
|
|
|
/** @var Config */ |
22
|
|
|
private $globalConfig; |
23
|
|
|
|
24
|
|
|
public function __construct(EnvironmentDataLoaderInterface $metadataLoader, Config $configGlobal) |
25
|
|
|
{ |
26
|
|
|
$this->globalConfig = $configGlobal; |
27
|
|
|
$this->metadataLoader = $metadataLoader; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function __invoke(EventProcessNodeInterface $event): void |
31
|
|
|
{ |
32
|
|
|
$val = new Entry($event->getNodeName()); |
33
|
|
|
|
34
|
|
|
$isConfiguredComposerPsr4 = new IsInConfigureComposerPsr4($this->metadataLoader); |
35
|
|
|
$rules = [ |
36
|
|
|
new FalsePositive($this->metadataLoader), |
37
|
|
|
new IsWithPrivateNamespace($this->globalConfig, $this->metadataLoader, $isConfiguredComposerPsr4), |
38
|
|
|
$isConfiguredComposerPsr4, |
39
|
|
|
new isInPrivateConfiguredEntries($this->globalConfig), |
40
|
|
|
]; |
41
|
|
|
|
42
|
|
|
foreach ($rules as $rule) { |
43
|
|
|
if ($rule->apply($val, $event)) { |
44
|
|
|
return; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
|