Conditions | 40 |
Paths | 124 |
Total Lines | 66 |
Code Lines | 56 |
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 |
||
121 | public static function compare( $value1, $value2, $operator ) { |
||
122 | switch ( $operator ) { |
||
123 | case '===': |
||
124 | $show = ( $value1 === $value2 ) ? true : false; |
||
125 | break; |
||
126 | case '==': |
||
127 | case '=': |
||
128 | case 'equals': |
||
129 | case 'equal': |
||
130 | $show = ( $value1 == $value2 ) ? true : false; |
||
131 | break; |
||
132 | case '!==': |
||
133 | $show = ( $value1 !== $value2 ) ? true : false; |
||
134 | break; |
||
135 | case '!=': |
||
136 | case 'not equal': |
||
137 | $show = ( $value1 != $value2 ) ? true : false; |
||
138 | break; |
||
139 | case '>=': |
||
140 | case 'greater or equal': |
||
141 | case 'equal or greater': |
||
142 | $show = ( $value2 >= $value1 ) ? true : false; |
||
143 | break; |
||
144 | case '<=': |
||
145 | case 'smaller or equal': |
||
146 | case 'equal or smaller': |
||
147 | $show = ( $value2 <= $value1 ) ? true : false; |
||
148 | break; |
||
149 | case '>': |
||
150 | case 'greater': |
||
151 | $show = ( $value2 > $value1 ) ? true : false; |
||
152 | break; |
||
153 | case '<': |
||
154 | case 'smaller': |
||
155 | $show = ( $value2 < $value1 ) ? true : false; |
||
156 | break; |
||
157 | case 'contains': |
||
158 | case 'in': |
||
159 | if ( is_array( $value1 ) && ! is_array( $value2 ) ) { |
||
160 | $array = $value1; |
||
161 | $string = $value2; |
||
162 | } elseif ( is_array( $value2 ) && ! is_array( $value1 ) ) { |
||
163 | $array = $value2; |
||
164 | $string = $value1; |
||
165 | } |
||
166 | if ( isset( $array ) && isset( $string ) ) { |
||
167 | if ( ! in_array( $string, $array, true ) ) { |
||
168 | $show = false; |
||
169 | } |
||
170 | } else { |
||
171 | if ( false === strrpos( $value1, $value2 ) && false === strpos( $value2, $value1 ) ) { |
||
172 | $show = false; |
||
173 | } |
||
174 | } |
||
175 | break; |
||
176 | default: |
||
177 | $show = ( $value1 == $value2 ) ? true : false; |
||
178 | |||
179 | } // End switch(). |
||
180 | |||
181 | if ( isset( $show ) ) { |
||
182 | return $show; |
||
183 | } |
||
184 | |||
185 | return true; |
||
186 | } |
||
187 | } |
||
188 |