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
![]() |
|||||
65 | return $this->getRequest()->getControllerName(); |
||||
0 ignored issues
–
show
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
![]() |
|||||
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 |