Completed
Push — master ( 14d1d8...f3cdf4 )
by Beniamin
03:22
created

ExpressionCollection::compile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
crap 2
1
<?php
2
3
/**
4
 * This file is part of Phuria SQL Builder package.
5
 *
6
 * Copyright (c) 2016 Beniamin Jonatan Šimko
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 Phuria\QueryBuilder\Expression;
13
14
/**
15
 * @author Beniamin Jonatan Šimko <[email protected]>
16
 */
17
class ExpressionCollection implements ExpressionInterface
18
{
19
    /**
20
     * @var ExpressionInterface[] $expressionList
21
     */
22
    private $expressionList;
23
24
    /**
25
     * @var string $separator
26
     */
27
    private $separator;
28
29
    /**
30
     * @param array  $expressionList
31
     * @param string $separator
32
     */
33 14
    public function __construct(array $expressionList, $separator = '')
34
    {
35 14
        $this->expressionList = $expressionList;
36 14
        $this->separator = $separator;
37 14
    }
38
39
    /**
40
     * @return ExpressionInterface[]
41
     */
42
    public function getExpressionList()
43
    {
44
        return $this->expressionList;
45
    }
46
47
    /**
48
     * @param string $separator
49
     *
50
     * @return ExpressionCollection
51
     */
52 5
    public function changeSeparator($separator)
53
    {
54 5
        return new self($this->expressionList, $separator);
55
    }
56
57
    /**
58
     * @inheritdoc
59
     */
60 14
    public function compile()
61
    {
62 14
        $elements = [];
63
64 14
        foreach ($this->expressionList as $expression) {
65 14
            $elements[] = $expression->compile();
66 14
        }
67
68 14
        return implode($this->separator, $elements);
69
    }
70
}