| Conditions | 16 |
| Paths | 594 |
| Total Lines | 75 |
| Code Lines | 37 |
| Lines | 8 |
| Ratio | 10.67 % |
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 |
||
| 13 | function __construct($params) |
||
|
|
|||
| 14 | { |
||
| 15 | View Code Duplication | if(isset($params['filter'])) |
|
| 16 | { |
||
| 17 | $this->filter = new \Data\Filter($params['filter']); |
||
| 18 | } |
||
| 19 | else if(isset($params['$filter'])) |
||
| 20 | { |
||
| 21 | $this->filter = new \Data\Filter($params['$filter']); |
||
| 22 | } |
||
| 23 | |||
| 24 | if(isset($params['$expand'])) |
||
| 25 | { |
||
| 26 | $this->expand = explode(',',$params['$expand']); |
||
| 27 | } |
||
| 28 | |||
| 29 | if(isset($params['select'])) |
||
| 30 | { |
||
| 31 | $this->select = explode(',',$params['select']); |
||
| 32 | } |
||
| 33 | else if(isset($params['$select'])) |
||
| 34 | { |
||
| 35 | $this->select = explode(',',$params['$select']); |
||
| 36 | } |
||
| 37 | |||
| 38 | if(isset($params['$orderby'])) |
||
| 39 | { |
||
| 40 | $this->orderby = array(); |
||
| 41 | $orderby = explode(',',$params['$orderby']); |
||
| 42 | $count = count($orderby); |
||
| 43 | for($i = 0; $i < $count; $i++) |
||
| 44 | { |
||
| 45 | $exp = explode(' ',$orderby[$i]); |
||
| 46 | if(count($exp) === 1) |
||
| 47 | { |
||
| 48 | //Default to assending |
||
| 49 | $this->orderby[$exp[0]] = 1; |
||
| 50 | } |
||
| 51 | else |
||
| 52 | { |
||
| 53 | switch($exp[1]) |
||
| 54 | { |
||
| 55 | case 'asc': |
||
| 56 | $this->orderby[$exp[0]] = 1; |
||
| 57 | break; |
||
| 58 | case 'desc': |
||
| 59 | $this->orderby[$exp[0]] = -1; |
||
| 60 | break; |
||
| 61 | default: |
||
| 62 | throw new Exception('Unknown orderby operation'); |
||
| 63 | } |
||
| 64 | } |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | if(isset($params['$top'])) |
||
| 69 | { |
||
| 70 | $this->top = $params['$top']; |
||
| 71 | } |
||
| 72 | |||
| 73 | if(isset($params['$skip'])) |
||
| 74 | { |
||
| 75 | $this->skip = $params['$skip']; |
||
| 76 | } |
||
| 77 | |||
| 78 | if(isset($params['$count']) && $params['$count'] === 'true') |
||
| 79 | { |
||
| 80 | $this->count = true; |
||
| 81 | } |
||
| 82 | |||
| 83 | if(isset($params['$seach'])) |
||
| 84 | { |
||
| 85 | throw new Exception('Search not yet implemented'); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 90 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.