Conditions | 12 |
Paths | 30 |
Total Lines | 42 |
Code Lines | 36 |
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 |
||
62 | public function matches($data) |
||
63 | { |
||
64 | $fieldName = $this->ConditionField()->Name; |
||
65 | $fieldValue = isset($data[$fieldName]) ? $data[$fieldName] : null; |
||
66 | $conditionValue = $this->ConditionValue; |
||
67 | $result = null; |
||
68 | switch ($this->ConditionOption) { |
||
69 | case 'IsBlank': |
||
70 | $result = empty($fieldValue); |
||
71 | break; |
||
72 | case 'IsNotBlank': |
||
73 | $result = !empty($fieldValue); |
||
74 | break; |
||
75 | case 'ValueLessThan': |
||
76 | $result = ($fieldValue < $conditionValue); |
||
77 | break; |
||
78 | case 'ValueLessThanEqual': |
||
79 | $result = ($fieldValue <= $conditionValue); |
||
80 | break; |
||
81 | case 'ValueGreaterThan': |
||
82 | $result = ($fieldValue > $conditionValue); |
||
83 | break; |
||
84 | case 'ValueGreaterThanEqual': |
||
85 | $result = ($fieldValue >= $conditionValue); |
||
86 | break; |
||
87 | case 'NotEquals': |
||
88 | case 'Equals': |
||
89 | $result = is_array($fieldValue) |
||
90 | ? in_array($conditionValue, $fieldValue) |
||
91 | : $fieldValue == $conditionValue; |
||
92 | |||
93 | if ($this->ConditionOption == 'NotEquals') { |
||
94 | $result = !($result); |
||
95 | } |
||
96 | break; |
||
97 | default: |
||
98 | throw new LogicException("Unhandled rule {$this->ConditionOption}"); |
||
99 | break; |
||
100 | } |
||
101 | |||
102 | return $result; |
||
103 | } |
||
104 | |||
175 |
This check marks private properties in classes that are never used. Those properties can be removed.