Completed
Push — master ( be9e17...f9656a )
by BruceScrutinizer
02:33
created

isFullyQualifiedNamespaceValid()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 17
rs 9.9666
1
<?php
2
declare(strict_types=1);
3
4
namespace NamespaceProtector\Db;
5
6
use NamespaceProtector\Entry\Entry;
7
8
final class BooleanMatchNameSpace implements MatchCollectionInterface
9
{
10
    /**
11
     * @param Iterable<mixed> $data
12
     */
13
    public function evaluate(iterable $data, Entry $matchMe): bool
14
    {
15
        foreach ($data as $item) {
16
            $currentEntry = \strtolower($item);
17
            $current = \strtolower($matchMe->get());
18
            if ($this->isFullyQualifiedNamespaceValid($current, $currentEntry)) {
19
                return true;
20
            }
21
        }
22
23
        return false;
24
    }
25
26
    private function isFullyQualifiedNamespaceValid(string $current, string $publicEntry): bool
27
    {
28
        if (strpos($current, $publicEntry) !== false) {
29
            $blockEntry = \explode('\\', $publicEntry);
30
            $blockCurrent = \explode('\\', $current);
31
32
            $endA = \end($blockEntry);
33
            $endB = \end($blockCurrent);
34
35
            if ($endA !== $endB) {
36
                return false;
37
            }
38
39
            return true;
40
        }
41
42
        return false;
43
    }
44
}
45