| Conditions | 16 |
| Paths | 11 |
| Total Lines | 39 |
| Code Lines | 24 |
| 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 |
||
| 181 | private function getRules($key) |
||
| 182 | {
|
||
| 183 | if(preg_match('@rule\((.*?)\)\r\n@is',$this->annotation,$rule)){
|
||
| 184 | |||
| 185 | $requestRules = $this->getReflection('rules');
|
||
| 186 | |||
| 187 | $rules = explode(":",$rule[1]);
|
||
| 188 | if(isset($this->inputs[$key]) && !is_array($this->inputs[$key])){
|
||
| 189 | foreach($rules as $rule){
|
||
| 190 | if(isset($requestRules[$rule])){
|
||
| 191 | if(!preg_match('@'.$requestRules[$rule].'@',$this->inputs[$key])){
|
||
| 192 | exception($rule,['key'=>$key]) |
||
| 193 | ->invalidArgument($key.' input value is not valid for '.$rule.' request rule'); |
||
| 194 | } |
||
| 195 | } |
||
| 196 | } |
||
| 197 | } |
||
| 198 | else{
|
||
| 199 | |||
| 200 | foreach ($this->inputs[$key] as $key=>$input){
|
||
|
|
|||
| 201 | |||
| 202 | if(!is_array($input)){
|
||
| 203 | foreach($rules as $rule){
|
||
| 204 | if(isset($requestRules[$rule])){
|
||
| 205 | if(!preg_match('@'.$requestRules[$rule].'@',$input)){
|
||
| 206 | exception($rule,['key'=>$key]) |
||
| 207 | ->invalidArgument($key.' input value is not valid for '.$rule.' request rule'); |
||
| 208 | } |
||
| 209 | } |
||
| 210 | } |
||
| 211 | } |
||
| 212 | else{
|
||
| 213 | |||
| 214 | foreach ($input as $ikey=>$item){
|
||
| 215 | foreach($rules as $rule){
|
||
| 216 | if(isset($requestRules[$rule])){
|
||
| 217 | if(!preg_match('@'.$requestRules[$rule].'@',$item)){
|
||
| 218 | exception($rule,['key'=>$item]) |
||
| 219 | ->invalidArgument($item.' input value is not valid for '.$rule.' request rule'); |
||
| 220 | } |
||
| 231 | } |