| Conditions | 11 |
| Paths | 33 |
| Total Lines | 46 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 30 | public function php($data) |
||
| 31 | { |
||
| 32 | $valid = true; |
||
| 33 | $fields = $this->form->Fields(); |
||
| 34 | |||
| 35 | foreach ($fields as $field) { |
||
| 36 | $valid = ($field->validate($this) && $valid); |
||
| 37 | } |
||
| 38 | |||
| 39 | if (!$this->required) { |
||
|
|
|||
| 40 | return $valid; |
||
| 41 | } |
||
| 42 | |||
| 43 | foreach ($this->required as $fieldName) { |
||
| 44 | if (!$fieldName) { |
||
| 45 | continue; |
||
| 46 | } |
||
| 47 | |||
| 48 | // get form field |
||
| 49 | if ($fieldName instanceof FormField) { |
||
| 50 | $formField = $fieldName; |
||
| 51 | $fieldName = $fieldName->getName(); |
||
| 52 | } else { |
||
| 53 | $formField = $fields->dataFieldByName($fieldName); |
||
| 54 | } |
||
| 55 | |||
| 56 | // get editable form field - owns display rules for field |
||
| 57 | $editableFormField = $this->getEditableFormFieldByName($fieldName); |
||
| 58 | |||
| 59 | $error = false; |
||
| 60 | |||
| 61 | // validate if there are no display rules or the field is conditionally visible |
||
| 62 | if (!$this->hasDisplayRules($editableFormField) || |
||
| 63 | $this->conditionalFieldEnabled($editableFormField, $data)) { |
||
| 64 | $error = $this->validateRequired($formField, $data); |
||
| 65 | } |
||
| 66 | |||
| 67 | // handle error case |
||
| 68 | if ($formField && $error) { |
||
| 69 | $this->handleError($formField, $fieldName); |
||
| 70 | |||
| 71 | $valid = false; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | return $valid; |
||
| 76 | } |
||
| 176 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.