Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
30 / 30 |
|
100.00% |
14 / 14 |
CRAP | |
100.00% |
1 / 1 |
AbstractClassGenerator | |
100.00% |
30 / 30 |
|
100.00% |
14 / 14 |
26 | |
100.00% |
1 / 1 |
addConstants | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
addConstant | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getConstant | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
3 | |||
hasConstant | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
hasConstants | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getConstants | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
removeConstant | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 | |||
addMethods | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
addMethod | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getMethod | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
3 | |||
hasMethod | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
hasMethods | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getMethods | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
removeMethod | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | /** |
3 | * Pop PHP Framework (http://www.popphp.org/) |
4 | * |
5 | * @link https://github.com/popphp/popphp-framework |
6 | * @author Nick Sagona, III <dev@nolainteractive.com> |
7 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
8 | * @license http://www.popphp.org/license New BSD License |
9 | */ |
10 | |
11 | /** |
12 | * @namespace |
13 | */ |
14 | namespace Pop\Code\Generator; |
15 | |
16 | /** |
17 | * Abstract class generator class |
18 | * |
19 | * @category Pop |
20 | * @package Pop\Code |
21 | * @author Nick Sagona, III <dev@nolainteractive.com> |
22 | * @copyright Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com) |
23 | * @license http://www.popphp.org/license New BSD License |
24 | * @version 5.0.0 |
25 | */ |
26 | abstract class AbstractClassGenerator extends AbstractGenerator |
27 | { |
28 | |
29 | use Traits\NameTrait, Traits\NamespaceTrait, Traits\DocblockTrait; |
30 | |
31 | /** |
32 | * Array of constant generator objects |
33 | * @var array |
34 | */ |
35 | protected array $constants = []; |
36 | |
37 | /** |
38 | * Array of method generator objects |
39 | * @var array |
40 | */ |
41 | protected array $methods = []; |
42 | |
43 | /** |
44 | * Add constants |
45 | * |
46 | * @param array $constants |
47 | * @return AbstractClassGenerator |
48 | */ |
49 | public function addConstants(array $constants): AbstractClassGenerator |
50 | { |
51 | foreach ($constants as $constant) { |
52 | $this->addConstant($constant); |
53 | } |
54 | return $this; |
55 | } |
56 | |
57 | /** |
58 | * Add a constant |
59 | * |
60 | * @param ConstantGenerator $constant |
61 | * @return AbstractClassGenerator |
62 | */ |
63 | public function addConstant(ConstantGenerator $constant): AbstractClassGenerator |
64 | { |
65 | $this->constants[$constant->getName()] = $constant; |
66 | return $this; |
67 | } |
68 | |
69 | /** |
70 | * Get a constant |
71 | * |
72 | * @param mixed $constant |
73 | * @return ConstantGenerator|null |
74 | */ |
75 | public function getConstant(mixed $constant): ConstantGenerator|null |
76 | { |
77 | $c = ($constant instanceof ConstantGenerator) ? $constant->getName() : $constant; |
78 | return (isset($this->constants[$c])) ? $this->constants[$c] : null; |
79 | } |
80 | |
81 | /** |
82 | * Has a constant |
83 | * |
84 | * @param mixed $constant |
85 | * @return bool |
86 | */ |
87 | public function hasConstant(mixed $constant): bool |
88 | { |
89 | $c = ($constant instanceof ConstantGenerator) ? $constant->getName() : $constant; |
90 | return (isset($this->constants[$c])); |
91 | } |
92 | |
93 | /** |
94 | * Has constants |
95 | * |
96 | * @return bool |
97 | */ |
98 | public function hasConstants(): bool |
99 | { |
100 | return (!empty($this->constants)); |
101 | } |
102 | |
103 | /** |
104 | * Get all constants |
105 | * |
106 | * @return array |
107 | */ |
108 | public function getConstants(): array |
109 | { |
110 | return $this->constants; |
111 | } |
112 | |
113 | /** |
114 | * Remove a constant |
115 | * |
116 | * @param mixed $constant |
117 | * @return AbstractClassGenerator |
118 | */ |
119 | public function removeConstant(mixed $constant): AbstractClassGenerator |
120 | { |
121 | $c = ($constant instanceof ConstantGenerator) ? $constant->getName() : $constant; |
122 | if (isset($this->constants[$c])) { |
123 | unset($this->constants[$c]); |
124 | } |
125 | return $this; |
126 | } |
127 | |
128 | /** |
129 | * Add methods |
130 | * |
131 | * @param array $methods |
132 | * @return AbstractClassGenerator |
133 | */ |
134 | public function addMethods(array $methods): AbstractClassGenerator |
135 | { |
136 | foreach ($methods as $method) { |
137 | $this->addMethod($method); |
138 | } |
139 | return $this; |
140 | } |
141 | |
142 | /** |
143 | * Add a method |
144 | * |
145 | * @param MethodGenerator $method |
146 | * @return AbstractClassGenerator |
147 | */ |
148 | public function addMethod(MethodGenerator $method): AbstractClassGenerator |
149 | { |
150 | $this->methods[$method->getName()] = $method; |
151 | return $this; |
152 | } |
153 | |
154 | /** |
155 | * Get a method |
156 | * |
157 | * @param mixed $method |
158 | * @return MethodGenerator|null |
159 | */ |
160 | public function getMethod(mixed $method): MethodGenerator|null |
161 | { |
162 | $m = ($method instanceof MethodGenerator) ? $method->getName() : $method; |
163 | return (isset($this->methods[$m])) ? $this->methods[$m] : null; |
164 | } |
165 | |
166 | /** |
167 | * Has a method |
168 | * |
169 | * @param mixed $method |
170 | * @return bool |
171 | */ |
172 | public function hasMethod(mixed $method): bool |
173 | { |
174 | $m = ($method instanceof MethodGenerator) ? $method->getName() : $method; |
175 | return (isset($this->methods[$m])); |
176 | } |
177 | |
178 | /** |
179 | * Has methods |
180 | * |
181 | * @return bool |
182 | */ |
183 | public function hasMethods(): bool |
184 | { |
185 | return (!empty($this->methods)); |
186 | } |
187 | |
188 | /** |
189 | * Get all methods |
190 | * |
191 | * @return array |
192 | */ |
193 | public function getMethods(): array |
194 | { |
195 | return $this->methods; |
196 | } |
197 | |
198 | /** |
199 | * Remove a method |
200 | * |
201 | * @param mixed $method |
202 | * @return AbstractClassGenerator |
203 | */ |
204 | public function removeMethod(mixed $method): AbstractClassGenerator |
205 | { |
206 | $m = ($method instanceof MethodGenerator) ? $method->getName() : $method; |
207 | if (isset($this->methods[$m])) { |
208 | unset($this->methods[$m]); |
209 | } |
210 | return $this; |
211 | } |
212 | |
213 | } |