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

Namespace_   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 12

5 Methods

Rating   Name   Duplication   Size   Complexity  
B include() 0 19 7
A getType() 0 3 1
A getFullyQualifiedNamespaceName() 0 7 2
A isNamespace() 0 3 1
A getFullyQualifiedClassName() 0 3 1
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