Passed
Push — master ( 056350...65484c )
by Satoshi
05:02
created

Namespace_::include()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 12
nc 6
nop 1
dl 0
loc 19
rs 8.8333
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace DependencyAnalyzer\DependencyGraph\FullyQualifiedStructuralElementName;
5
6
use DependencyAnalyzer\DependencyGraph\FullyQualifiedStructuralElementName;
7
8
class Namespace_ extends Base
9
{
10
    public function getType(): string
11
    {
12
        return FullyQualifiedStructuralElementName::TYPE_NAMESPACE;
13
    }
14
15
    public function include(Base $that): bool
16
    {
17
        if ($this->toString() === '\\') {
18
            // Pattern likely '\\' will match with all className.
19
            return true;
20
        } elseif ($this->isSame($that)) {
21
            return true;
22
        } elseif (count($this->getFullyQualifiedNamespaceName()) > count($this->getFullyQualifiedNamespaceName())) {
23
            return false;
24
        }
25
26
        $namesOfThat = $that->getFullyQualifiedNamespaceName();
27
        foreach ($this->getFullyQualifiedNamespaceName() as $index => $name) {
28
            if (!isset($namesOfThat[$index]) || $namesOfThat[$index] !== $name) {
29
                return false;
30
            }
31
        }
32
33
        return true;
34
    }
35
36
    public function isNamespace(): bool
37
    {
38
        return true;
39
    }
40
41
    public function getFullyQualifiedNamespaceName(): array
42
    {
43
        if ($this->toString() === '\\') {
44
            return [];
45
        }
46
47
        return explode('\\', trim($this->toString(), '\\'));
48
    }
49
50
    public function getFullyQualifiedClassName(): ?array
51
    {
52
        return null;
53
    }
54
}
55