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

Name   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A from() 0 3 1
A __construct() 0 4 1
A __toString() 0 3 1
A namespace() 0 3 1
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