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

SelectClauseExpression::isEmpty()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4.128

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
ccs 4
cts 5
cp 0.8
rs 9.2
cc 4
eloc 5
nc 2
nop 0
crap 4.128
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
}