ClassName::name()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Phpactor\ClassFileConverter\Domain;
4
5
final class ClassName
6
{
7
    private $fullyQualifiedName;
8
9
    private function __construct()
10
    {
11
    }
12
13
    public static function fromString($string)
14
    {
15
        $new = new self();
16
        $new->fullyQualifiedName = $string;
17
18
        return $new;
19
    }
20
21
    public function __toString()
22
    {
23
        return $this->fullyQualifiedName;
24
    }
25
26
    public function namespace()
27
    {
28
        return substr($this->fullyQualifiedName, 0, (int) strrpos($this->fullyQualifiedName, '\\'));
29
    }
30
31
    public function name()
32
    {
33
        $pos = strrpos($this->fullyQualifiedName, '\\');
34
        if (false === $pos) {
35
            return $this->fullyQualifiedName;
36
        }
37
        return substr($this->fullyQualifiedName, $pos + 1);
38
    }
39
40
    public function beginsWith($prefix)
41
    {
42
        return 0 === strpos($this->fullyQualifiedName, $prefix);
43
    }
44
}
45