Completed
Push — 1.8 ( eae5ca )
by Luis
10:56
created

Name::namespace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * PHP version 7.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Code;
9
10
class Name
11
{
12
    /** @var string */
13
    private $name;
14
15
    /** @var string[] Packages, sub-packages and class/interface/trait name */
16
    private $parts;
17
18
    public static function from(string $text): Name
19
    {
20
        return new Name($text);
21
    }
22
23
    public function namespace(): string
0 ignored issues
show
Coding Style introduced by
Possible parse error: non-abstract method defined as abstract
Loading history...
24
    {
25
        return implode('\\', \array_slice($this->parts, 0, -1));
26
    }
27
28
    public function __toString()
29
    {
30
        return $this->name;
31
    }
32
33
    private function __construct(string $name)
34
    {
35
        $this->parts = explode('\\', $name);
36
        $this->name = $this->parts[substr_count($name, '\\')];
37
    }
38
}
39