Test Failed
Push — master ( 15b6af...d076c2 )
by BruceScrutinizer
08:02
created

IsInConfigureComposerPsr4::apply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 10
1
<?php declare(strict_types=1);
2
3
namespace NamespaceProtector\Rule;
4
5
use NamespaceProtector\Entry\Entry;
6
use NamespaceProtector\Db\BooleanMatchNameSpace;
7
use NamespaceProtector\EnvironmentDataLoaderInterface;
8
use NamespaceProtector\Parser\Node\Event\EventProcessNodeInterface;
9
10
class IsInConfigureComposerPsr4 implements RuleInterface
11
{
12
    private EnvironmentDataLoaderInterface  $metadataLoader;
13
14
    public function __construct(EnvironmentDataLoaderInterface $metadataLoader)
15
    {
16
        $this->metadataLoader = $metadataLoader;
17
    }
18
19
    public function apply(Entry $entry, EventProcessNodeInterface $event): bool
20
    {
21
        $val = $this->stripFirstSlash($entry);
22
23
        return $this->metadataLoader->getCollectComposerNamespace()->booleanSearch(new BooleanMatchNameSpace(), $val);
24
    }
25
26
    private function stripFirstSlash(Entry $token): Entry
27
    {
28
        if ($token->get()[0] === '\\') {
29
            return new Entry(substr($token->get(), 1, strlen($token->get())));
30
        }
31
32
        return $token;
33
    }
34
}
35