| Total Complexity | 41 |
| Total Lines | 349 |
| 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 $fillOutService; |
||
| 28 | |||
| 29 | protected $defaultInputOption; |
||
| 30 | |||
| 31 | protected $hasDefaultValue = false; |
||
| 32 | |||
| 33 | protected $validation; |
||
| 34 | |||
| 35 | protected $depositLicense = null; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var \EWW\Dpf\Domain\Model\InputOptionList $inputOptionList |
||
| 39 | */ |
||
| 40 | protected $inputOptionList; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var string |
||
| 44 | */ |
||
| 45 | protected $dataType; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var int |
||
| 49 | */ |
||
| 50 | protected $gndFieldUid; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * consent |
||
| 54 | * |
||
| 55 | * @var boolean |
||
| 56 | */ |
||
| 57 | protected $consent; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var int |
||
| 61 | */ |
||
| 62 | protected $maxInputLength; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * help text |
||
| 66 | * |
||
| 67 | * @var string |
||
| 68 | */ |
||
| 69 | protected $helpText = ''; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var string |
||
| 73 | */ |
||
| 74 | protected $objectType = ''; |
||
| 75 | |||
| 76 | public function getValue() |
||
| 77 | { |
||
| 78 | return $this->value; |
||
| 79 | } |
||
| 80 | |||
| 81 | public function setValue($value, $defaultValue = '') |
||
| 82 | { |
||
| 83 | |||
| 84 | $this->hasDefaultValue = !empty($defaultValue); |
||
| 85 | |||
| 86 | if (empty($value)) { |
||
| 87 | switch ($this->inputField) { |
||
| 88 | case \EWW\Dpf\Domain\Model\MetadataObject::select: |
||
| 89 | if (!empty($defaultValue)) { |
||
| 90 | $this->value = $this->defaultInputOption; |
||
| 91 | } else { |
||
| 92 | $this->value = ''; |
||
| 93 | } |
||
| 94 | break; |
||
| 95 | |||
| 96 | case \EWW\Dpf\Domain\Model\MetadataObject::checkbox: |
||
| 97 | if (!empty($defaultValue)) { |
||
| 98 | $this->value = 'yes'; |
||
| 99 | } else { |
||
| 100 | $this->value = ''; |
||
| 101 | } |
||
| 102 | break; |
||
| 103 | |||
| 104 | default: |
||
| 105 | $this->value = $defaultValue; |
||
| 106 | break; |
||
| 107 | } |
||
| 108 | } else { |
||
| 109 | $this->value = $value; |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | public function getInputField() |
||
| 114 | { |
||
| 115 | return $this->inputField; |
||
| 116 | } |
||
| 117 | |||
| 118 | public function setInputField($inputField) |
||
| 119 | { |
||
| 120 | $this->inputField = $inputField; |
||
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * |
||
| 125 | * @return array |
||
| 126 | */ |
||
| 127 | public function getInputOptions() |
||
| 128 | { |
||
| 129 | $inputOptions = array(); |
||
| 130 | |||
| 131 | if ($this->inputOptionList) { |
||
| 132 | $inputOptions[''] = ''; |
||
| 133 | foreach ($this->inputOptionList->getInputOptions() as $option => $label) { |
||
| 134 | $this->inputOptions[$option] = $label; |
||
|
|
|||
| 135 | } |
||
| 136 | |||
| 137 | $this->defaultInputOption = trim($this->inputOptionList->getDefaultValue()); |
||
| 138 | } |
||
| 139 | |||
| 140 | return $inputOptions; |
||
| 141 | } |
||
| 142 | |||
| 143 | /** |
||
| 144 | * @return \EWW\Dpf\Domain\Model\InputOptionList |
||
| 145 | */ |
||
| 146 | public function getInputOptionList() |
||
| 147 | { |
||
| 148 | return $this->inputOptionList; |
||
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * |
||
| 153 | * @param \EWW\Dpf\Domain\Model\InputOptionList $inputOptionList |
||
| 154 | */ |
||
| 155 | public function setInputOptionList(\EWW\Dpf\Domain\Model\InputOptionList $inputOptionList = null) |
||
| 156 | { |
||
| 157 | $this->inputOptionList = $inputOptionList; |
||
| 158 | } |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Returns the fillOutService |
||
| 162 | * |
||
| 163 | * @return string $fillOutService |
||
| 164 | */ |
||
| 165 | public function getFillOutService() |
||
| 166 | { |
||
| 167 | return $this->fillOutService; |
||
| 168 | } |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Sets the fillOutService |
||
| 172 | * |
||
| 173 | * @param string $fillOutService |
||
| 174 | * @return void |
||
| 175 | */ |
||
| 176 | public function setFillOutService($fillOutService) |
||
| 177 | { |
||
| 178 | $this->fillOutService = $fillOutService; |
||
| 179 | } |
||
| 180 | |||
| 181 | /** |
||
| 182 | * Returns the consent |
||
| 183 | * |
||
| 184 | * @return boolean $consent |
||
| 185 | */ |
||
| 186 | public function getConsent() |
||
| 187 | { |
||
| 188 | return $this->consent; |
||
| 189 | } |
||
| 190 | |||
| 191 | /** |
||
| 192 | * Sets the consent |
||
| 193 | * |
||
| 194 | * @param boolean $consent |
||
| 195 | * @return void |
||
| 196 | */ |
||
| 197 | public function setConsent($consent) |
||
| 198 | { |
||
| 199 | $this->consent = boolval($consent); |
||
| 200 | } |
||
| 201 | |||
| 202 | public function getHasDefaultValue() |
||
| 203 | { |
||
| 204 | return $this->hasDefaultValue; |
||
| 205 | } |
||
| 206 | |||
| 207 | public function getValidation() |
||
| 208 | { |
||
| 209 | return $this->validation; |
||
| 210 | } |
||
| 211 | |||
| 212 | public function setValidation($validation) |
||
| 213 | { |
||
| 214 | $this->validation = $validation; |
||
| 215 | } |
||
| 216 | |||
| 217 | /** |
||
| 218 | * Gets the data type of the field, e.g. DATE |
||
| 219 | * |
||
| 220 | * @return string |
||
| 221 | */ |
||
| 222 | public function getDataType() |
||
| 223 | { |
||
| 224 | return $this->dataType; |
||
| 225 | } |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Sets the data type of the field, e.g. DATE |
||
| 229 | * |
||
| 230 | * @param string $dataType |
||
| 231 | * @return void |
||
| 232 | */ |
||
| 233 | public function setDataType($dataType) |
||
| 234 | { |
||
| 235 | $this->dataType = $dataType; |
||
| 236 | } |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Gets the uid of the field which is |
||
| 240 | * linked with the gnd field |
||
| 241 | * |
||
| 242 | * @return int |
||
| 243 | */ |
||
| 244 | public function getGndFieldUid() { |
||
| 245 | return $this->gndFieldUid; |
||
| 246 | } |
||
| 247 | |||
| 248 | /** |
||
| 249 | * Sets the uid of the field which is |
||
| 250 | * linked with the gnd field |
||
| 251 | * |
||
| 252 | * @param int $fieldId |
||
| 253 | * @return void |
||
| 254 | */ |
||
| 255 | public function setGndFieldUid($fieldId) { |
||
| 256 | $this->gndFieldUid = $fieldId; |
||
| 257 | } |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Gets the max length of characters for the input field. |
||
| 261 | * |
||
| 262 | * @return int |
||
| 263 | */ |
||
| 264 | public function getMaxInputLength() { |
||
| 265 | return $this->maxInputLength; |
||
| 266 | } |
||
| 267 | |||
| 268 | /** |
||
| 269 | * Sets the max length of characters for the input field. |
||
| 270 | * |
||
| 271 | * @return int |
||
| 272 | */ |
||
| 273 | public function setMaxInputLength($maxInputLength) { |
||
| 274 | $this->maxInputLength = $maxInputLength; |
||
| 275 | } |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @return string |
||
| 279 | */ |
||
| 280 | public function getObjectType(): string |
||
| 283 | } |
||
| 284 | |||
| 285 | /** |
||
| 286 | * @param string $objectType |
||
| 287 | */ |
||
| 288 | public function setObjectType(string $objectType): void |
||
| 289 | { |
||
| 290 | $this->objectType = $objectType; |
||
| 291 | } |
||
| 292 | |||
| 293 | /** |
||
| 294 | * @return mixed |
||
| 295 | */ |
||
| 296 | public function getDepositLicense() |
||
| 297 | { |
||
| 298 | return $this->depositLicense; |
||
| 299 | } |
||
| 300 | |||
| 301 | /** |
||
| 302 | * @param mixed $depositLicense |
||
| 303 | */ |
||
| 304 | public function setDepositLicense($depositLicense): void |
||
| 305 | { |
||
| 306 | $this->depositLicense = $depositLicense; |
||
| 307 | } |
||
| 308 | |||
| 309 | /** |
||
| 310 | * @return string |
||
| 311 | */ |
||
| 312 | public function getHelpText(): string |
||
| 313 | { |
||
| 314 | return $this->helpText; |
||
| 315 | } |
||
| 316 | |||
| 317 | /** |
||
| 318 | * @param string $helpText |
||
| 319 | */ |
||
| 320 | public function setHelpText(string $helpText): void |
||
| 323 | } |
||
| 324 | |||
| 325 | public function getHelpTextLong() |
||
| 335 | } |
||
| 336 | } |
||
| 337 | } |
||
| 338 | |||
| 339 | public function getHelpTextShort() |
||
| 340 | { |
||
| 341 | if ($this->helpText) { |
||
| 342 | $domDocument = new \DOMDocument(); |
||
| 343 | $domDocument->loadXML("<html>" . $this->helpText . "</html>"); |
||
| 344 | $xpath = \EWW\Dpf\Helper\XPath::create($domDocument); |
||
| 345 | $nodes = $xpath->query("//p"); |
||
| 346 | if ($nodes->length > 0) { |
||
| 347 | return $nodes->item(0)->nodeValue; |
||
| 348 | } |
||
| 349 | } |
||
| 350 | } |
||
| 351 | |||
| 352 | /** |
||
| 353 | * @return mixed |
||
| 354 | */ |
||
| 355 | public function getFile() |
||
| 356 | { |
||
| 357 | return $this->file; |
||
| 358 | } |
||
| 359 | |||
| 360 | /** |
||
| 361 | * @param mixed $file |
||
| 362 | */ |
||
| 363 | public function setFile($file): void |
||
| 366 | } |
||
| 367 | |||
| 368 | } |
||
| 369 |