Completed
Push — master ( aa02db...c8592c )
by WEBEWEB
09:51
created

ArrayQueryBuilderType::toSql()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 2
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the jquery-querybuilder-bundle package.
5
 *
6
 * (c) 2019 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\JQuery\QueryBuilderBundle\Decorator\Type;
13
14
use WBW\Bundle\JQuery\QueryBuilderBundle\API\QueryBuilderRule;
15
use WBW\Bundle\JQuery\QueryBuilderBundle\API\QueryBuilderRuleInterface;
16
use WBW\Bundle\JQuery\QueryBuilderBundle\Decorator\QueryBuilderDecoratorFactory;
17
18
/**
19
 * Array QueryBuilder type.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\JQuery\QueryBuilderBundle\Decorator\Type
23
 */
24
class ArrayQueryBuilderType extends AbstractQueryBuilderType {
25
26
    const DEFAULT_IMPLODER = "{{implode}}";
27
28
    /**
29
     * Constructor.
30
     */
31
    public function __construct() {
32
        parent::__construct(null);
33
    }
34
35
    /**
36
     * {@inheritDoc}
37
     */
38
    public function toSql(QueryBuilderRuleInterface $rule, bool $wrap = false): string {
39
40
        /** @var string[] $sql */
41
        $sql = [];
42
43
        foreach ($rule->getValue() as $current) {
44
45
            $qbd = QueryBuilderDecoratorFactory::newQueryBuilderType($rule->getType());
46
47
            $qbr = new QueryBuilderRule();
48
            $qbr->setType($rule->getType());
49
            $qbr->setValue($current);
50
51
            $sql[] = $qbd->toSql($qbr, $wrap);
52
        }
53
54
        return implode("{{implode}}", $sql);
55
    }
56
}
57