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

HasNameTrait::generateNameFromClass()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2.1481

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
ccs 2
cts 3
cp 0.6667
cc 2
nc 2
nop 0
crap 2.1481
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