Passed
Push — master ( 148695...692a71 )
by Gabriel
04:05 queued 10s
created

NameWorksTrait   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
eloc 17
c 2
b 0
f 0
dl 0
loc 70
rs 10
ccs 0
cts 21
cp 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A initName() 0 3 1
A setName() 0 3 1
A getClassName() 0 3 1
A getName() 0 7 2
A getFullName() 0 7 2
A generateName() 0 7 2
1
<?php
2
3
namespace Nip\Controllers\Traits;
4
5
use Nip\Utility\Traits\NameWorksTrait as UtilityNameWorksTrait;
6
7
/**
8
 * Trait NameWorksTrait
9
 * @package Nip\Controllers\Traits
10
 */
11
trait NameWorksTrait
12
{
13
    protected $fullName = null;
14
15
    protected $name = null;
16
17
    use UtilityNameWorksTrait;
18
19
//    protected function inflectName()
20
//    {
21
//        $name = str_replace("Controller", "", get_class($this));
22
//        $this->name = inflector()->unclassify($name);
23
//    }
24
25
    /**
26
     * @return string
27
     */
28
    public function getClassName()
29
    {
30
        return str_replace("Controller", "", get_class($this));
31
    }
32
33
34
    /**
35
     * @return string
36
     */
37
    public function getName()
38
    {
39
        if ($this->name === null) {
40
            $this->initName();
41
        }
42
43
        return $this->name;
44
    }
45
46
    /**
47
     * @param string $name
48
     */
49
    public function setName($name)
50
    {
51
        $this->name = $name;
52
    }
53
54
    public function initName()
55
    {
56
        $this->setName($this->generateName());
57
    }
58
59
    /**
60
     * @return mixed
61
     */
62
    protected function generateName()
63
    {
64
        if ($this->hasRequest()) {
0 ignored issues
show
Bug introduced by
It seems like hasRequest() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
        if ($this->/** @scrutinizer ignore-call */ hasRequest()) {
Loading history...
65
            return $this->getRequest()->getControllerName();
0 ignored issues
show
Bug introduced by
It seems like getRequest() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
            return $this->/** @scrutinizer ignore-call */ getRequest()->getControllerName();
Loading history...
66
        }
67
        $class = $this->getClassFirstName();
68
        return str_replace('Controller', '', $class);
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    public function getFullName()
75
    {
76
        if ($this->fullName === null) {
77
            $this->fullName = inflector()->unclassify($this->getClassName());
78
        }
79
80
        return $this->fullName;
81
    }
82
}
83