IdentifierTrait   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 78
rs 10
c 1
b 0
f 0
wmc 9
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPath() 0 4 1
A getNamespace() 0 4 1
A getName() 0 12 3
A getFullName() 0 6 2
A getReflection() 0 8 2
1
<?php
2
/*
3
 * This file is part of the Borobudur-Kernel package.
4
 *
5
 * (c) Hexacodelabs <http://hexacodelabs.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Borobudur\Kernel;
12
13
use ReflectionObject;
14
15
/**
16
 * @author      Iqbal Maulana <[email protected]>
17
 * @created     8/7/15
18
 */
19
trait IdentifierTrait
20
{
21
    /**
22
     * @var ReflectionObject
23
     */
24
    private $reflection;
25
26
    /**
27
     * @var string
28
     */
29
    private $name;
30
31
    /**
32
     * Get class file path.
33
     *
34
     * @return string
35
     */
36
    public function getPath()
37
    {
38
        return str_replace('\\', '/', dirname($this->getReflection()->getFileName()));
39
    }
40
41
    /**
42
     * Get class namespace.
43
     *
44
     * @return string
45
     */
46
    public function getNamespace()
47
    {
48
        return $this->getReflection()->getNamespaceName();
49
    }
50
51
    /**
52
     * Get class name (short name).
53
     *
54
     * @return string
55
     */
56
    public function getName()
57
    {
58
        if (null !== $this->name) {
59
60
            return $this->name;
61
        }
62
63
        $name = get_class($this);
64
        $pos = strrpos($name, '\\');
65
66
        return $this->name = false === $pos ? $name : substr($name, $pos + 1);
67
    }
68
69
    /**
70
     * Get class full name.
71
     *
72
     * Return namespace and class name.
73
     *
74
     * @return string
75
     */
76
    public function getFullName()
77
    {
78
        $namespace = $this->getNamespace();
79
80
        return (false === empty($namespace) ? $namespace.'\\' : '').$this->getName();
81
    }
82
83
    /**
84
     * Get reflection object.
85
     *
86
     * @return ReflectionObject
87
     */
88
    protected function getReflection()
89
    {
90
        if (null === $this->reflection) {
91
            $this->reflection = new ReflectionObject($this);
92
        }
93
94
        return $this->reflection;
95
    }
96
}
97