| Conditions | 12 |
| Paths | 26 |
| Total Lines | 41 |
| Code Lines | 35 |
| 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 |
||
| 64 | public function matches($data) |
||
| 65 | { |
||
| 66 | $fieldName = $this->ConditionField()->Name; |
||
| 67 | $fieldValue = isset($data[$fieldName]) ? $data[$fieldName] : null; |
||
| 68 | $conditionValue = $this->ConditionValue; |
||
| 69 | $result = null; |
||
| 70 | switch ($this->ConditionOption) { |
||
| 71 | case 'IsBlank': |
||
| 72 | $result = empty($fieldValue); |
||
| 73 | break; |
||
| 74 | case 'IsNotBlank': |
||
| 75 | $result = !empty($fieldValue); |
||
| 76 | break; |
||
| 77 | case 'ValueLessThan': |
||
| 78 | $result = ($fieldValue < $conditionValue); |
||
| 79 | break; |
||
| 80 | case 'ValueLessThanEqual': |
||
| 81 | $result = ($fieldValue <= $conditionValue); |
||
| 82 | break; |
||
| 83 | case 'ValueGreaterThan': |
||
| 84 | $result = ($fieldValue > $conditionValue); |
||
| 85 | break; |
||
| 86 | case 'ValueGreaterThanEqual': |
||
| 87 | $result = ($fieldValue >= $conditionValue); |
||
| 88 | break; |
||
| 89 | case 'NotEquals': |
||
| 90 | case 'Equals': |
||
| 91 | $result = is_array($fieldValue) |
||
| 92 | ? in_array($conditionValue, $fieldValue) |
||
| 93 | : $fieldValue == $conditionValue; |
||
| 94 | |||
| 95 | if ($this->ConditionOption == 'NotEquals') { |
||
| 96 | $result = !($result); |
||
| 97 | } |
||
| 98 | break; |
||
| 99 | default: |
||
| 100 | throw new LogicException("Unhandled rule {$this->ConditionOption}"); |
||
| 101 | break; |
||
| 102 | } |
||
| 103 | |||
| 104 | return $result; |
||
| 105 | } |
||
| 162 |