| Conditions | 10 |
| Paths | 44 |
| Total Lines | 44 |
| Code Lines | 26 |
| 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 |
||
| 44 | public function build(LikeConditionInterface $expression, array &$params = []): string |
||
| 45 | { |
||
| 46 | $operator = strtoupper($expression->getOperator()); |
||
| 47 | $column = $expression->getColumn(); |
||
| 48 | $values = $expression->getValue(); |
||
| 49 | $escape = $expression->getEscapingReplacements(); |
||
| 50 | |||
| 51 | if ($escape === []) { |
||
| 52 | $escape = $this->escapingReplacements; |
||
| 53 | } |
||
| 54 | |||
| 55 | [$andor, $not, $operator] = $this->parseOperator($operator); |
||
| 56 | |||
| 57 | if (!is_array($values)) { |
||
| 58 | $values = [$values]; |
||
| 59 | } |
||
| 60 | |||
| 61 | if (empty($values)) { |
||
| 62 | return $not ? '' : '0=1'; |
||
| 63 | } |
||
| 64 | |||
| 65 | if ($column instanceof ExpressionInterface) { |
||
| 66 | $column = $this->queryBuilder->buildExpression($column, $params); |
||
| 67 | } elseif (!str_contains($column, '(')) { |
||
| 68 | $column = $this->queryBuilder->quoter()->quoteColumnName($column); |
||
| 69 | } |
||
| 70 | |||
| 71 | $escapeSql = $this->getEscapeSql(); |
||
| 72 | $parts = []; |
||
| 73 | |||
| 74 | /** @psalm-var string[] $values */ |
||
| 75 | foreach ($values as $value) { |
||
| 76 | if ($value instanceof ExpressionInterface) { |
||
| 77 | $phName = $this->queryBuilder->buildExpression($value, $params); |
||
| 78 | } else { |
||
| 79 | $phName = $this->queryBuilder->bindParam( |
||
| 80 | $escape === null ? $value : ('%' . strtr($value, $escape) . '%'), |
||
| 81 | $params |
||
| 82 | ); |
||
| 83 | } |
||
| 84 | $parts[] = "{$column} {$operator} {$phName}{$escapeSql}"; |
||
| 85 | } |
||
| 86 | |||
| 87 | return implode($andor, $parts); |
||
| 88 | } |
||
| 125 |