Conditions | 10 |
Paths | 16 |
Total Lines | 27 |
Code Lines | 20 |
Lines | 0 |
Ratio | 0 % |
Tests | 23 |
CRAP Score | 10 |
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 |
||
58 | 3 | public function fromArray(array $jWhere) |
|
59 | { |
||
60 | 3 | $where = new Where(); |
|
61 | |||
62 | 3 | foreach($jWhere as $item){ |
|
63 | 3 | if(is_array($item)){ |
|
64 | 3 | if(!in_array($item[0], $this->allowed)) { |
|
65 | 1 | throw new InvalidCommandException(); |
|
66 | } |
||
67 | 2 | $method = $item[0]; |
|
68 | 2 | unset($item[0]); |
|
69 | 2 | $where = call_user_func_array([$where, $method], $item); |
|
70 | 2 | } |
|
71 | 3 | if(is_string($item)){ |
|
72 | 3 | if(in_array($item, $this->allowed)) |
|
73 | 3 | if($item == 'and') |
|
74 | 3 | $where = $where->and; |
|
75 | 3 | else if ($item == 'or') |
|
76 | 3 | $where = $where->or; |
|
77 | 3 | else if ($item == 'nest') |
|
78 | 3 | $where = $where->nest(); |
|
79 | 2 | else if ($item == 'unnest') |
|
80 | 2 | $where = $where->unnest(); |
|
81 | 3 | } |
|
82 | 3 | } |
|
83 | 2 | return $where; |
|
84 | } |
||
85 | } |
||
86 |