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

IsConfiguredInThirdPartyApp   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 30
rs 10
c 1
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A apply() 0 12 3
A check() 0 3 1
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