| Conditions | 22 |
| Paths | 777 |
| Total Lines | 70 |
| Code Lines | 37 |
| 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 |
||
| 45 | public function build(InConditionInterface $expression, array &$params = []): string |
||
| 46 | { |
||
| 47 | $column = $expression->getColumn(); |
||
| 48 | $nullConditionOperator = ''; |
||
| 49 | $operator = strtoupper($expression->getOperator()); |
||
| 50 | $values = $expression->getValues(); |
||
| 51 | |||
| 52 | if ($column === []) { |
||
| 53 | /** no columns to test against */ |
||
| 54 | return $operator === 'IN' ? '0=1' : ''; |
||
| 55 | } |
||
| 56 | |||
| 57 | if ($values instanceof QueryInterface) { |
||
| 58 | return $this->buildSubqueryInCondition($operator, $column, $values, $params); |
||
| 59 | } |
||
| 60 | |||
| 61 | if (!is_array($values) && !is_iterable($values)) { |
||
| 62 | /** ensure values is an array */ |
||
| 63 | $values = (array) $values; |
||
| 64 | } |
||
| 65 | |||
| 66 | if (is_array($column)) { |
||
| 67 | if (count($column) > 1) { |
||
| 68 | return $this->buildCompositeInCondition($operator, $column, $values, $params); |
||
|
|
|||
| 69 | } |
||
| 70 | |||
| 71 | /** @var mixed */ |
||
| 72 | $column = reset($column); |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($column instanceof Iterator) { |
||
| 76 | if (iterator_count($column) > 1) { |
||
| 77 | return $this->buildCompositeInCondition($operator, $column, $values, $params); |
||
| 78 | } |
||
| 79 | |||
| 80 | $column->rewind(); |
||
| 81 | /** @var mixed */ |
||
| 82 | $column = $column->current(); |
||
| 83 | } |
||
| 84 | |||
| 85 | if (is_array($values)) { |
||
| 86 | $rawValues = $values; |
||
| 87 | } else { |
||
| 88 | $rawValues = $this->getRawValuesFromTraversableObject($values); |
||
| 89 | } |
||
| 90 | |||
| 91 | if (is_string($column) && in_array(null, $rawValues, true)) { |
||
| 92 | $nullCondition = $this->getNullCondition($operator, $column); |
||
| 93 | $nullConditionOperator = $operator === 'IN' ? 'OR' : 'AND'; |
||
| 94 | } |
||
| 95 | |||
| 96 | $sqlValues = $this->buildValues($expression, $values, $params); |
||
| 97 | |||
| 98 | if (empty($sqlValues)) { |
||
| 99 | return empty($nullCondition) ? ($operator === 'IN' ? '0=1' : '') : (string) $nullCondition; |
||
| 100 | } |
||
| 101 | |||
| 102 | if (is_string($column) && !str_contains($column, '(')) { |
||
| 103 | $column = $this->queryBuilder->quoter()->quoteColumnName($column); |
||
| 104 | } |
||
| 105 | |||
| 106 | if (count($sqlValues) > 1) { |
||
| 107 | $sql = "$column $operator (" . implode(', ', $sqlValues) . ')'; |
||
| 108 | } else { |
||
| 109 | $operator = $operator === 'IN' ? '=' : '<>'; |
||
| 110 | $sql = (string) $column . $operator . reset($sqlValues); |
||
| 111 | } |
||
| 112 | |||
| 113 | /** @var int|string|null $nullCondition */ |
||
| 114 | return isset($nullCondition) ? sprintf('%s %s %s', $sql, $nullConditionOperator, $nullCondition) : $sql; |
||
| 115 | } |
||
| 269 |