| Total Complexity | 14 |
| Total Lines | 57 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 8 | class Namespace_ extends Base |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @param string $elementName |
||
| 12 | * @inheritDoc |
||
| 13 | */ |
||
| 14 | public function __construct(string $elementName) |
||
| 15 | { |
||
| 16 | if (substr($elementName, -1) !== '\\') { |
||
| 17 | $elementName .= '\\'; |
||
| 18 | } |
||
| 19 | parent::__construct($elementName); |
||
| 20 | } |
||
| 21 | |||
| 22 | public function getType(): string |
||
| 23 | { |
||
| 24 | return FullyQualifiedStructuralElementName::TYPE_NAMESPACE; |
||
| 25 | } |
||
| 26 | |||
| 27 | public function include(Base $that): bool |
||
| 28 | { |
||
| 29 | if ($this->toString() === '\\') { |
||
| 30 | // Pattern likely '\\' will match with all className. |
||
| 31 | return true; |
||
| 32 | } elseif ($this->isSame($that)) { |
||
| 33 | return true; |
||
| 34 | } elseif (count($this->getFullyQualifiedNamespaceNameAsArray()) > count($this->getFullyQualifiedNamespaceNameAsArray())) { |
||
| 35 | return false; |
||
| 36 | } |
||
| 37 | |||
| 38 | $namesOfThat = $that->getFullyQualifiedNamespaceNameAsArray(); |
||
| 39 | foreach ($this->getFullyQualifiedNamespaceNameAsArray() as $index => $name) { |
||
| 40 | if (!isset($namesOfThat[$index]) || $namesOfThat[$index] !== $name) { |
||
| 41 | return false; |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | return true; |
||
| 46 | } |
||
| 47 | |||
| 48 | public function isNamespace(): bool |
||
| 49 | { |
||
| 50 | return true; |
||
| 51 | } |
||
| 52 | |||
| 53 | public function getFullyQualifiedNamespaceNameAsArray(): array |
||
| 54 | { |
||
| 55 | if ($this->toString() === '\\') { |
||
| 56 | return []; |
||
| 57 | } |
||
| 58 | |||
| 59 | return explode('\\', trim($this->toString(), '\\')); |
||
| 60 | } |
||
| 61 | |||
| 62 | public function getFullyQualifiedClassNameAsArray(): ?array |
||
| 65 | } |
||
| 66 | } |
||
| 67 |