Total Complexity | 42 |
Total Lines | 359 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Complex classes like DocumentFormField often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DocumentFormField, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
17 | class DocumentFormField extends AbstractFormElement |
||
18 | { |
||
19 | protected $file; |
||
20 | |||
21 | protected $value; |
||
22 | |||
23 | protected $inputField; |
||
24 | |||
25 | protected $selectOptions; |
||
26 | |||
27 | protected $inputOptions; |
||
28 | |||
29 | protected $fillOutService; |
||
30 | |||
31 | protected $defaultInputOption; |
||
32 | |||
33 | protected $hasDefaultValue = false; |
||
34 | |||
35 | protected $validation; |
||
36 | |||
37 | protected $depositLicense = null; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $validationErrorMessage = ''; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $validator; |
||
48 | |||
49 | /** |
||
50 | * @var int |
||
51 | */ |
||
52 | protected $gndFieldUid; |
||
53 | |||
54 | /** |
||
55 | * consent |
||
56 | * |
||
57 | * @var boolean |
||
58 | */ |
||
59 | protected $consent; |
||
60 | |||
61 | /** |
||
62 | * @var int |
||
63 | */ |
||
64 | protected $maxInputLength; |
||
65 | |||
66 | /** |
||
67 | * help text |
||
68 | * |
||
69 | * @var string |
||
70 | */ |
||
71 | protected $helpText = ''; |
||
72 | |||
73 | /** |
||
74 | * @var string |
||
75 | */ |
||
76 | protected $objectType = ''; |
||
77 | |||
78 | public function getValue() |
||
79 | { |
||
80 | return $this->value; |
||
81 | } |
||
82 | |||
83 | public function setValue($value, $defaultValue = '') |
||
84 | { |
||
85 | |||
86 | $this->hasDefaultValue = !empty($defaultValue); |
||
87 | |||
88 | if (empty($value)) { |
||
89 | switch ($this->inputField) { |
||
90 | case \EWW\Dpf\Domain\Model\MetadataObject::select: |
||
91 | if (!empty($defaultValue)) { |
||
92 | $this->value = $this->defaultInputOption; |
||
93 | } else { |
||
94 | $this->value = ''; |
||
95 | } |
||
96 | break; |
||
97 | |||
98 | case \EWW\Dpf\Domain\Model\MetadataObject::checkbox: |
||
99 | if (!empty($defaultValue)) { |
||
100 | $this->value = 'yes'; |
||
101 | } else { |
||
102 | $this->value = ''; |
||
103 | } |
||
104 | break; |
||
105 | |||
106 | default: |
||
107 | $this->value = $defaultValue; |
||
108 | break; |
||
109 | } |
||
110 | } else { |
||
111 | $this->value = $value; |
||
112 | } |
||
113 | } |
||
114 | |||
115 | public function getInputField() |
||
116 | { |
||
117 | return $this->inputField; |
||
118 | } |
||
119 | |||
120 | public function setInputField($inputField) |
||
121 | { |
||
122 | $this->inputField = $inputField; |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * |
||
127 | * @return array |
||
128 | */ |
||
129 | public function getInputOptions() |
||
130 | { |
||
131 | return $this->inputOptions; |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * |
||
136 | * @param \EWW\Dpf\Domain\Model\InputOptionList $inputOptionList |
||
137 | */ |
||
138 | public function setInputOptions(\EWW\Dpf\Domain\Model\InputOptionList $inputOptionList = null) |
||
139 | { |
||
140 | |||
141 | $this->inputOptions = array(); |
||
142 | |||
143 | if ($inputOptionList) { |
||
144 | $this->inputOptions[''] = ''; |
||
145 | foreach ($inputOptionList->getInputOptions() as $option => $label) { |
||
146 | $this->inputOptions[$option] = $label; |
||
147 | } |
||
148 | |||
149 | $this->defaultInputOption = trim($inputOptionList->getDefaultValue()); |
||
150 | } |
||
151 | |||
152 | } |
||
153 | |||
154 | /** |
||
155 | * Returns the fillOutService |
||
156 | * |
||
157 | * @return string $fillOutService |
||
158 | */ |
||
159 | public function getFillOutService() |
||
160 | { |
||
161 | return $this->fillOutService; |
||
162 | } |
||
163 | |||
164 | /** |
||
165 | * Sets the fillOutService |
||
166 | * |
||
167 | * @param string $fillOutService |
||
168 | * @return void |
||
169 | */ |
||
170 | public function setFillOutService($fillOutService) |
||
171 | { |
||
172 | $this->fillOutService = $fillOutService; |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * Returns the consent |
||
177 | * |
||
178 | * @return boolean $consent |
||
179 | */ |
||
180 | public function getConsent() |
||
181 | { |
||
182 | return $this->consent; |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * Sets the consent |
||
187 | * |
||
188 | * @param boolean $consent |
||
189 | * @return void |
||
190 | */ |
||
191 | public function setConsent($consent) |
||
192 | { |
||
193 | $this->consent = boolval($consent); |
||
194 | } |
||
195 | |||
196 | public function getHasDefaultValue() |
||
197 | { |
||
198 | return $this->hasDefaultValue; |
||
199 | } |
||
200 | |||
201 | public function getValidation() |
||
202 | { |
||
203 | return $this->validation; |
||
204 | } |
||
205 | |||
206 | public function setValidation($validation) |
||
207 | { |
||
208 | $this->validation = $validation; |
||
209 | } |
||
210 | |||
211 | /** |
||
212 | * Gets the data type of the field, e.g. DATE |
||
213 | * |
||
214 | * @return string |
||
215 | */ |
||
216 | public function getValidator() |
||
217 | { |
||
218 | return $this->validator; |
||
219 | } |
||
220 | |||
221 | /** |
||
222 | * Sets the data type of the field, e.g. DATE |
||
223 | * |
||
224 | * @param string $validator |
||
225 | * @return void |
||
226 | */ |
||
227 | public function setValidator($validator) |
||
228 | { |
||
229 | $this->validator = $validator; |
||
230 | } |
||
231 | |||
232 | /** |
||
233 | * Gets the uid of the field which is |
||
234 | * linked with the gnd field |
||
235 | * |
||
236 | * @return int |
||
237 | */ |
||
238 | public function getGndFieldUid() { |
||
239 | return $this->gndFieldUid; |
||
240 | } |
||
241 | |||
242 | /** |
||
243 | * Sets the uid of the field which is |
||
244 | * linked with the gnd field |
||
245 | * |
||
246 | * @param int $fieldId |
||
247 | * @return void |
||
248 | */ |
||
249 | public function setGndFieldUid($fieldId) { |
||
250 | $this->gndFieldUid = $fieldId; |
||
251 | } |
||
252 | |||
253 | /** |
||
254 | * Gets the max length of characters for the input field. |
||
255 | * |
||
256 | * @return int |
||
257 | */ |
||
258 | public function getMaxInputLength() { |
||
259 | return $this->maxInputLength; |
||
260 | } |
||
261 | |||
262 | /** |
||
263 | * Sets the max length of characters for the input field. |
||
264 | * |
||
265 | * @return int |
||
266 | */ |
||
267 | public function setMaxInputLength($maxInputLength) { |
||
268 | $this->maxInputLength = $maxInputLength; |
||
269 | } |
||
270 | |||
271 | /** |
||
272 | * @return string |
||
273 | */ |
||
274 | public function getObjectType(): string |
||
277 | } |
||
278 | |||
279 | /** |
||
280 | * @param string $objectType |
||
281 | */ |
||
282 | public function setObjectType(string $objectType): void |
||
283 | { |
||
284 | $this->objectType = $objectType; |
||
285 | } |
||
286 | |||
287 | /** |
||
288 | * @return mixed |
||
289 | */ |
||
290 | public function getDepositLicense() |
||
291 | { |
||
292 | return $this->depositLicense; |
||
293 | } |
||
294 | |||
295 | /** |
||
296 | * @param mixed $depositLicense |
||
297 | */ |
||
298 | public function setDepositLicense($depositLicense): void |
||
299 | { |
||
300 | $this->depositLicense = $depositLicense; |
||
301 | } |
||
302 | |||
303 | /** |
||
304 | * @return string |
||
305 | */ |
||
306 | public function getHelpText(): string |
||
307 | { |
||
308 | return $this->helpText; |
||
309 | } |
||
310 | |||
311 | /** |
||
312 | * @param string $helpText |
||
313 | */ |
||
314 | public function setHelpText(string $helpText): void |
||
317 | } |
||
318 | |||
319 | public function getHelpTextLong() |
||
329 | } |
||
330 | } |
||
331 | } |
||
332 | |||
333 | public function getHelpTextShort() |
||
334 | { |
||
335 | if ($this->helpText) { |
||
336 | $domDocument = new \DOMDocument(); |
||
337 | $domDocument->loadXML("<html>" . $this->helpText . "</html>"); |
||
338 | $xpath = \EWW\Dpf\Helper\XPath::create($domDocument); |
||
339 | $nodes = $xpath->query("//p"); |
||
340 | if ($nodes->length > 0) { |
||
341 | return $nodes->item(0)->nodeValue; |
||
342 | } |
||
343 | } |
||
344 | } |
||
345 | |||
346 | /** |
||
347 | * @return mixed |
||
348 | */ |
||
349 | public function getFile() |
||
350 | { |
||
351 | return $this->file; |
||
352 | } |
||
353 | |||
354 | /** |
||
355 | * @param mixed $file |
||
356 | */ |
||
357 | public function setFile($file): void |
||
360 | } |
||
361 | |||
362 | /** |
||
363 | * @return string |
||
364 | */ |
||
365 | public function getValidationErrorMessage(): string |
||
368 | } |
||
369 | |||
370 | /** |
||
371 | * @param string $validationErrorMessage |
||
372 | */ |
||
373 | public function setValidationErrorMessage(string $validationErrorMessage): void |
||
374 | { |
||
375 | $this->validationErrorMessage = $validationErrorMessage; |
||
376 | } |
||
377 | |||
378 | } |
||
379 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.