Conditions | 10 |
Paths | 193 |
Total Lines | 68 |
Code Lines | 45 |
Lines | 20 |
Ratio | 29.41 % |
Changes | 6 | ||
Bugs | 1 | Features | 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 |
||
46 | public static function toObject(array $desc) |
||
47 | { |
||
48 | if (isset($desc['SELECT'])) { |
||
49 | $select = new Select(); |
||
50 | |||
51 | $columns = array_map(function ($item) { |
||
52 | return NodeFactory::toObject($item); |
||
53 | }, $desc['SELECT']); |
||
54 | $columns = NodeFactory::simplify($columns); |
||
55 | $select->setColumns($columns); |
||
|
|||
56 | |||
57 | if (isset($desc['OPTIONS'])) { |
||
58 | $options = $desc['OPTIONS']; |
||
59 | $key = array_search('DISTINCT', $options); |
||
60 | if ($key !== false) { |
||
61 | $select->setDistinct(true); |
||
62 | unset($options[$key]); |
||
63 | } else { |
||
64 | $select->setDistinct(false); |
||
65 | } |
||
66 | $select->setOptions($options); |
||
67 | } |
||
68 | |||
69 | if (isset($desc['FROM'])) { |
||
70 | $from = self::mapArrayToNodeObjectList($desc['FROM']); |
||
71 | $select->setFrom($from); |
||
72 | } |
||
73 | |||
74 | View Code Duplication | if (isset($desc['WHERE'])) { |
|
75 | $where = self::mapArrayToNodeObjectList($desc['WHERE']); |
||
76 | $where = NodeFactory::simplify($where); |
||
77 | $select->setWhere($where); |
||
78 | } |
||
79 | |||
80 | View Code Duplication | if (isset($desc['GROUP'])) { |
|
81 | $group = self::mapArrayToNodeObjectList($desc['GROUP']); |
||
82 | $group = NodeFactory::simplify($group); |
||
83 | $select->setGroup($group); |
||
84 | } |
||
85 | |||
86 | View Code Duplication | if (isset($desc['HAVING'])) { |
|
87 | $having = self::mapArrayToNodeObjectList($desc['HAVING']); |
||
88 | $having = NodeFactory::simplify($having); |
||
89 | $select->setHaving($having); |
||
90 | } |
||
91 | |||
92 | View Code Duplication | if (isset($desc['ORDER'])) { |
|
93 | $order = self::mapArrayToNodeObjectList($desc['ORDER']); |
||
94 | $order = NodeFactory::simplify($order); |
||
95 | $select->setOrder($order); |
||
96 | } |
||
97 | |||
98 | if (isset($desc['LIMIT'])) { |
||
99 | $descLimit = self::checkLimitDesc($desc['LIMIT']); |
||
100 | |||
101 | $limit = NodeFactory::toObject($descLimit['limit']); |
||
102 | //$limit = NodeFactory::simplify($limit); |
||
103 | $select->setLimit($limit); |
||
104 | |||
105 | $offset = NodeFactory::toObject($descLimit['offset']); |
||
106 | //$offset = NodeFactory::simplify($offset); |
||
107 | $select->setOffset($offset); |
||
108 | } |
||
109 | return $select; |
||
110 | } else { |
||
111 | throw new \BadMethodCallException('Unknown query'); |
||
112 | } |
||
113 | } |
||
114 | |||
151 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: