| Conditions | 10 |
| Paths | 33 |
| Total Lines | 42 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 33 | public function php($data) |
||
| 34 | { |
||
| 35 | $valid = true; |
||
| 36 | $fields = $this->form->Fields(); |
||
| 37 | |||
| 38 | foreach ($fields as $field) { |
||
| 39 | $valid = ($field->validate($this) && $valid); |
||
| 40 | } |
||
| 41 | |||
| 42 | if (empty($this->required)) { |
||
| 43 | return $valid; |
||
| 44 | } |
||
| 45 | |||
| 46 | foreach ($this->required as $fieldName) { |
||
| 47 | if (!$fieldName) { |
||
| 48 | continue; |
||
| 49 | } |
||
| 50 | |||
| 51 | // get form field |
||
| 52 | if ($fieldName instanceof FormField) { |
||
| 53 | $formField = $fieldName; |
||
| 54 | $fieldName = $fieldName->getName(); |
||
| 55 | } else { |
||
| 56 | $formField = $fields->dataFieldByName($fieldName); |
||
| 57 | } |
||
| 58 | |||
| 59 | // get editable form field - owns display rules for field |
||
| 60 | $editableFormField = $this->getEditableFormFieldByName($fieldName); |
||
| 61 | |||
| 62 | // Validate if the field is displayed |
||
| 63 | $error = |
||
| 64 | $editableFormField->isDisplayed($data) && |
||
| 65 | $this->validateRequired($formField, $data); |
||
| 66 | |||
| 67 | // handle error case |
||
| 68 | if ($formField && $error) { |
||
| 69 | $this->handleError($formField, $fieldName); |
||
| 70 | $valid = false; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | return $valid; |
||
| 75 | } |
||
| 151 |