Completed
Push — master ( f3cdf4...360009 )
by Beniamin
04:07
created

SelectClauseExpression   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 88.24%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 1
cbo 3
dl 0
loc 48
ccs 15
cts 17
cp 0.8824
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A isEmpty() 0 10 4
A compile() 0 12 3
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 SelectClauseExpression extends QueryClauseExpression
18
{
19
    /**
20
     * @var ExpressionInterface $hints
21
     */
22
    private $hints;
23
24
    /**
25
     * @param ExpressionInterface $hints
26
     * @param ExpressionInterface $expression
27
     * @param bool                $quietWhenEmpty
28
     */
29 21
    public function __construct(ExpressionInterface $hints, ExpressionInterface $expression, $quietWhenEmpty = true)
30
    {
31 21
        $this->hints = $hints;
32 21
        parent::__construct(static::CLAUSE_SELECT, $expression, $quietWhenEmpty);
33 21
    }
34
35
    /**
36
     * @inheritdoc
37
     */
38 21
    public function isEmpty()
39
    {
40 21
        $hints = $this->hints;
41
42 21
        if (parent::isEmpty() && $hints instanceof ExpressionCollection && $hints->isEmpty()) {
43
            return true;
44
        }
45
46 21
        return false;
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52 21
    public function compile()
53
    {
54 21
        if ($this->isQuietWhenEmpty() && $this->isEmpty()) {
55
            return '';
56
        }
57
58 21
        return implode(' ', array_filter([
59 21
            $this->getClause(),
60 21
            $this->hints->compile(),
61 21
            $this->getWrappedExpression()->compile()
62 21
        ]));
63
    }
64
}