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