Passed
Push — master ( 9be6d3...56d82e )
by Gabriel
04:12
created

HasNameTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 1
b 0
f 0
dl 0
loc 41
rs 10
ccs 13
cts 14
cp 0.9286

4 Methods

Rating   Name   Duplication   Size   Complexity  
A generateNameFromClass() 0 5 2
A initName() 0 3 1
A getName() 0 7 2
A generateName() 0 6 1
1
<?php
2
3
namespace ByTIC\Models\SmartProperties\Properties\AbstractProperty\Traits;
4
5
use ReflectionClass;
6
7
/**
8
 * Trait HasNameTrait
9
 * @package ByTIC\Models\SmartProperties\Properties\AbstractProperty\Traits
10
 */
11
trait HasNameTrait
12
{
13
14
    protected $name = null;
15
16
    /**
17
     * @return string
18
     */
19 15
    public function getName()
20
    {
21 15
        if ($this->name == null) {
22 15
            $this->initName();
23
        }
24
25 15
        return $this->name;
26
    }
27
28 15
    public function initName()
29
    {
30 15
        $this->name = $this->generateName();
31 15
    }
32
33
    /**
34
     * @return string
35
     */
36 15
    public function generateName()
37
    {
38 15
        $name = $this->generateNameFromClass();
39 15
        $name = inflector()->unclassify($name);
40
41 15
        return $name;
42
    }
43
44
    /**
45
     * @return string
46
     */
47 12
    protected function generateNameFromClass()
48
    {
49
        try {
50 12
            return (new ReflectionClass($this))->getShortName();
51
        } catch (\ReflectionException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
52
        }
53
    }
54
}
55