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