Conditions | 24 |
Paths | 3897 |
Total Lines | 73 |
Code Lines | 44 |
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 |
||
34 | public function build(ExpressionInterface $expression, array &$params = []) |
||
35 | { |
||
36 | $operator = strtoupper($expression->getOperator()); |
||
|
|||
37 | $column = $expression->getColumn(); |
||
38 | $values = $expression->getValues(); |
||
39 | |||
40 | if ($column === []) { |
||
41 | // no columns to test against |
||
42 | return $operator === 'IN' ? '0=1' : ''; |
||
43 | } |
||
44 | |||
45 | if ($values instanceof Query) { |
||
46 | return $this->buildSubqueryInCondition($operator, $column, $values, $params); |
||
47 | } |
||
48 | |||
49 | if (!is_array($values) && !$values instanceof \Traversable) { |
||
50 | // ensure values is an array |
||
51 | $values = (array) $values; |
||
52 | } |
||
53 | |||
54 | if (is_array($column)) { |
||
55 | if (count($column) > 1) { |
||
56 | return $this->buildCompositeInCondition($operator, $column, $values, $params); |
||
57 | } |
||
58 | $column = reset($column); |
||
59 | } |
||
60 | |||
61 | if ($column instanceof \Traversable) { |
||
62 | if (iterator_count($column) > 1) { |
||
63 | return $this->buildCompositeInCondition($operator, $column, $values, $params); |
||
64 | } |
||
65 | $column->rewind(); |
||
66 | $column = $column->current(); |
||
67 | } |
||
68 | |||
69 | if ($column instanceof ExpressionInterface) { |
||
70 | $column = $column->expression; |
||
71 | } |
||
72 | |||
73 | if (is_array($values)) { |
||
74 | $rawValues = $values; |
||
75 | } elseif ($values instanceof \Traversable) { |
||
76 | $rawValues = $this->getRawValuesFromTraversableObject($values); |
||
77 | } |
||
78 | |||
79 | $nullCondition = null; |
||
80 | $nullConditionOperator = null; |
||
81 | if (isset($rawValues) && in_array(null, $rawValues, true)) { |
||
82 | $nullCondition = $this->getNullCondition($operator, $column); |
||
83 | $nullConditionOperator = $operator === 'IN' ? 'OR' : 'AND'; |
||
84 | } |
||
85 | |||
86 | $sqlValues = $this->buildValues($expression, $values, $params); |
||
87 | if (empty($sqlValues)) { |
||
88 | if ($nullCondition === null) { |
||
89 | return $operator === 'IN' ? '0=1' : ''; |
||
90 | } |
||
91 | return $nullCondition; |
||
92 | } |
||
93 | |||
94 | if (strpos($column, '(') === false) { |
||
95 | $column = $this->queryBuilder->db->quoteColumnName($column); |
||
96 | } |
||
97 | if (count($sqlValues) > 1) { |
||
98 | $sql = "$column $operator (" . implode(', ', $sqlValues) . ')'; |
||
99 | } else { |
||
100 | $operator = $operator === 'IN' ? '=' : '<>'; |
||
101 | $sql = $column . $operator . reset($sqlValues); |
||
102 | } |
||
103 | |||
104 | return $nullCondition !== null && $nullConditionOperator !== null |
||
105 | ? sprintf('%s %s %s', $sql, $nullConditionOperator, $nullCondition) |
||
106 | : $sql; |
||
107 | } |
||
264 |