Conditions | 21 |
Paths | 14 |
Total Lines | 69 |
Code Lines | 39 |
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 |
||
185 | private function getRules($key) |
||
186 | { |
||
187 | if(preg_match('@rule\((.*?)\)|rule\((.*?)\)\r\n@is',$this->annotation,$rule)){ |
||
188 | |||
189 | $requestRules = $this->getReflection('rules'); |
||
190 | |||
191 | $rules = explode(":",$rule[1]); |
||
192 | if(isset($this->inputs[$key]) && !is_array($this->inputs[$key])){ |
||
193 | foreach($rules as $rule){ |
||
194 | |||
195 | $ruleExplode = explode('#',$rule); |
||
196 | $rule = $ruleExplode[0]; |
||
197 | |||
198 | if(isset($requestRules[$rule])){ |
||
199 | if(!preg_match('@'.$requestRules[$rule].'@',$this->inputs[$key])){ |
||
200 | exception($rule,['key'=>$key.':'.$this->inputs[$key]]) |
||
201 | ->invalidArgument($key.':'.$this->inputs[$key].' input value is not valid for '.$rule.' request rule'); |
||
202 | } |
||
203 | } |
||
204 | |||
205 | //rule method |
||
206 | if(!isset($requestRules[$rule])){ |
||
207 | $this->request->call(function() use($rule,$key,$ruleExplode){ |
||
208 | if(method_exists($this,$ruleMethod = '__rule'.ucfirst($rule))){ |
||
209 | if(isset($ruleExplode[1])){ |
||
210 | |||
211 | $reValueList = []; |
||
212 | foreach (explode(',',$ruleExplode[1]) as $reValue){ |
||
213 | $reValueExplode = explode('=',$reValue); |
||
214 | $reValueListKey = $reValueExplode[0]; |
||
215 | $reValueListValue = (isset($reValueExplode[1])) ? $reValueExplode[1] : null; |
||
216 | |||
217 | $reValueList[$reValueListKey] = $reValueListValue; |
||
218 | |||
219 | } |
||
220 | |||
221 | $this->{$ruleMethod}($key,$this->inputs[$key],$reValueList); |
||
222 | } |
||
223 | else{ |
||
224 | $this->{$ruleMethod}($key,$this->inputs[$key]); |
||
225 | } |
||
226 | |||
227 | } |
||
228 | }); |
||
229 | } |
||
230 | } |
||
231 | } |
||
232 | else{ |
||
233 | |||
234 | foreach ($this->inputs[$key] as $ikey=>$input){ |
||
235 | |||
236 | if(!is_array($input)){ |
||
237 | foreach($rules as $rule){ |
||
238 | if(isset($requestRules[$rule])){ |
||
239 | if(!preg_match('@'.$requestRules[$rule].'@',$input)){ |
||
240 | exception($rule,['key'=>''.$key.':'.$input]) |
||
241 | ->invalidArgument($key.':'.$input.' input value is not valid for '.$rule.' request rule'); |
||
242 | } |
||
243 | } |
||
244 | } |
||
245 | } |
||
246 | else{ |
||
247 | |||
248 | foreach ($input as $ikey=>$item){ |
||
|
|||
249 | foreach($rules as $rule){ |
||
250 | if(isset($requestRules[$rule])){ |
||
251 | if(!preg_match('@'.$requestRules[$rule].'@',$item)){ |
||
252 | exception($rule,['key'=>''.$key.':'.$item]) |
||
253 | ->invalidArgument($key.':'.$item.' input value is not valid for '.$rule.' request rule'); |
||
254 | } |
||
265 | } |