These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @link http://www.yiiframework.com/ |
||
4 | * @copyright Copyright (c) 2008 Yii Software LLC |
||
5 | * @license http://www.yiiframework.com/license/ |
||
6 | */ |
||
7 | |||
8 | namespace yii\db\conditions; |
||
9 | |||
10 | use yii\db\ExpressionBuilderInterface; |
||
11 | use yii\db\ExpressionBuilderTrait; |
||
12 | use yii\db\ExpressionInterface; |
||
13 | |||
14 | /** |
||
15 | * Class ConjunctionConditionBuilder builds objects of abstract class [[ConjunctionCondition]] |
||
16 | * |
||
17 | * @author Dmytro Naumenko <[email protected]> |
||
18 | * @since 2.0.14 |
||
19 | */ |
||
20 | class ConjunctionConditionBuilder implements ExpressionBuilderInterface |
||
21 | { |
||
22 | use ExpressionBuilderTrait; |
||
23 | |||
24 | |||
25 | /** |
||
26 | * Method builds the raw SQL from the $expression that will not be additionally |
||
27 | * escaped or quoted. |
||
28 | * |
||
29 | * @param ExpressionInterface|ConjunctionCondition $condition the expression to be built. |
||
30 | * @param array $params the binding parameters. |
||
31 | * @return string the raw SQL that will not be additionally escaped or quoted. |
||
32 | */ |
||
33 | 230 | public function build(ExpressionInterface $condition, array &$params = []) |
|
34 | { |
||
35 | 230 | $parts = $this->buildExpressionsFrom($condition, $params); |
|
36 | |||
37 | 230 | if (empty($parts)) { |
|
38 | return ''; |
||
39 | } |
||
40 | |||
41 | 230 | if (count($parts) === 1) { |
|
42 | 92 | return reset($parts); |
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
43 | } |
||
44 | |||
45 | 156 | return '(' . implode(") {$condition->getOperator()} (", $parts) . ')'; |
|
46 | } |
||
47 | |||
48 | /** |
||
49 | * Builds expressions, that are stored in $condition |
||
50 | * |
||
51 | * @param ExpressionInterface|ConjunctionCondition $condition the expression to be built. |
||
52 | * @param array $params the binding parameters. |
||
53 | * @return string[] |
||
54 | */ |
||
55 | 230 | private function buildExpressionsFrom(ExpressionInterface $condition, &$params = []) |
|
56 | { |
||
57 | 230 | $parts = []; |
|
58 | 230 | foreach ($condition->getExpressions() as $condition) { |
|
59 | 230 | if (is_array($condition)) { |
|
60 | 205 | $condition = $this->queryBuilder->buildCondition($condition, $params); |
|
61 | } |
||
62 | 230 | if ($condition instanceof ExpressionInterface) { |
|
63 | 9 | $condition = $this->queryBuilder->buildExpression($condition, $params); |
|
64 | } |
||
65 | 230 | if ($condition !== '') { |
|
66 | 230 | $parts[] = $condition; |
|
67 | } |
||
68 | } |
||
69 | |||
70 | 230 | return $parts; |
|
71 | } |
||
72 | } |
||
73 |