CompilerPayload::appendSQL()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
1
<?php
2
3
/**
4
 * This file is part of UnderQuery 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\UnderQuery\QueryCompiler;
13
14
use Phuria\UnderQuery\QueryBuilder\BuilderInterface;
15
16
/**
17
 * @author Beniamin Jonatan Šimko <[email protected]>
18
 */
19
class CompilerPayload
20
{
21
    /**
22
     * @var string
23
     */
24
    private $actualSQL;
25
26
    /**
27
     * @var BuilderInterface
28
     */
29
    private $builder;
30
31
    /**
32
     * @param BuilderInterface $builder
33
     * @param string|null      $actualSQL
34
     */
35
    public function __construct(BuilderInterface $builder, $actualSQL = null)
36
    {
37
        $this->actualSQL = $actualSQL;
38
        $this->builder = $builder;
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function getActualSQL()
45
    {
46
        return $this->actualSQL;
47
    }
48
49
    /**
50
     * @return BuilderInterface
51
     */
52
    public function getBuilder()
53
    {
54
        return $this->builder;
55
    }
56
57
    /**
58
     * @param string $newSQL
59
     *
60
     * @return CompilerPayload
61
     */
62
    public function updateSQL($newSQL)
63
    {
64
        return new CompilerPayload($this->builder, $newSQL);
65
    }
66
67
    /**
68
     * @param string $newSQL
69
     *
70
     * @return CompilerPayload
71
     */
72
    public function appendSQL($newSQL)
73
    {
74
        if ($newSQL) {
75
            return $this->updateSQL($this->actualSQL . ' ' . $newSQL);
76
        }
77
78
        return $this;
79
    }
80
}