Conditions | 12 |
Paths | 50 |
Total Lines | 27 |
Code Lines | 18 |
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 |
||
37 | protected function buildCompositeInCondition($operator, $columns, $values, &$params) |
||
38 | { |
||
39 | $quotedColumns = []; |
||
40 | foreach ($columns as $i => $column) { |
||
41 | if ($column instanceof ExpressionInterface) { |
||
42 | $column = $column->expression; |
||
|
|||
43 | } |
||
44 | $quotedColumns[$i] = strpos($column, '(') === false ? $this->queryBuilder->db->quoteColumnName($column) : $column; |
||
45 | } |
||
46 | $vss = []; |
||
47 | foreach ($values as $value) { |
||
48 | $vs = []; |
||
49 | foreach ($columns as $i => $column) { |
||
50 | if ($column instanceof ExpressionInterface) { |
||
51 | $column = $column->expression; |
||
52 | } |
||
53 | if (isset($value[$column])) { |
||
54 | $phName = $this->queryBuilder->bindParam($value[$column], $params); |
||
55 | $vs[] = $quotedColumns[$i] . ($operator === 'IN' ? ' = ' : ' != ') . $phName; |
||
56 | } else { |
||
57 | $vs[] = $quotedColumns[$i] . ($operator === 'IN' ? ' IS' : ' IS NOT') . ' NULL'; |
||
58 | } |
||
59 | } |
||
60 | $vss[] = '(' . implode($operator === 'IN' ? ' AND ' : ' OR ', $vs) . ')'; |
||
61 | } |
||
62 | |||
63 | return '(' . implode($operator === 'IN' ? ' OR ' : ' AND ', $vss) . ')'; |
||
64 | } |
||
66 |