Test Failed
Push — master ( 36eeda...83b81c )
by BruceScrutinizer
08:00
created

IsConfiguredInThirdPartyApp::apply()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
nc 3
nop 2
dl 0
loc 12
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace NamespaceProtector\Rule;
4
5
use NamespaceProtector\Entry\Entry;
6
use NamespaceProtector\Config\Config;
7
use NamespaceProtector\EnvironmentDataLoaderInterface;
8
use NamespaceProtector\Parser\Node\MatchedResultInterface;
9
use NamespaceProtector\Parser\Node\Event\EventProcessNodeInterface;
10
11
class IsConfiguredInThirdPartyApp implements RuleInterface
12
{
13
    private Config $config;
14
    private EnvironmentDataLoaderInterface $environmentDataLoader;
15
16
    public function __construct(
17
        EnvironmentDataLoaderInterface $environmentDataLoader,
18
        Config $config
19
    ) {
20
        $this->environmentDataLoader = $environmentDataLoader;
21
        $this->config = $config;
22
    }
23
24
    public function apply(Entry $entry, EventProcessNodeInterface $event): bool
25
    {
26
        if ($this->config->getMode() !== Config::MODE_AUTODISCOVER) {
27
            return false;
28
        }
29
30
        if (!$this->check($entry)->matched()) {
31
            return true;
32
        }
33
34
        $event->foundError();
35
        return true;
36
    }
37
38
    private function check(Entry $currentNamespaceAccess): MatchedResultInterface
39
    {
40
        return $this->environmentDataLoader->vendorNamespaces()->hasNamespace($currentNamespaceAccess);
41
    }
42
}
43