Completed
Push — master ( bf07e5...f61ec4 )
by Beniamin
02:20
created

AbstractBuilder::buildQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 5
nc 1
nop 1
crap 1
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\SQLBuilder\QueryBuilder;
13
14
use Phuria\SQLBuilder\Connection\ConnectionInterface;
15
use Phuria\SQLBuilder\Parameter\ParameterManagerInterface;
16
use Phuria\SQLBuilder\Query;
17
use Phuria\SQLBuilder\QueryCompiler\QueryCompilerInterface;
18
use Phuria\SQLBuilder\TableFactory\TableFactoryInterface;
19
20
/**
21
 * @author Beniamin Jonatan Šimko <[email protected]>
22
 */
23
abstract class AbstractBuilder implements BuilderInterface
24
{
25
    /**
26
     * @var TableFactoryInterface
27
     */
28
    private $tableFactory;
29
30
    /**
31
     * @var QueryCompilerInterface
32
     */
33
    private $queryCompiler;
34
35
    /**
36
     * @var ParameterManagerInterface
37
     */
38
    private $parameterManager;
39
40
    /**
41
     * @param TableFactoryInterface     $tableFactory
42
     * @param QueryCompilerInterface    $queryCompiler
43
     * @param ParameterManagerInterface $parameterManager
44
     */
45 34
    public function __construct(
46
        TableFactoryInterface $tableFactory,
47
        QueryCompilerInterface $queryCompiler,
48
        ParameterManagerInterface $parameterManager
49
    ) {
50 34
        $this->tableFactory = $tableFactory;
51 34
        $this->queryCompiler = $queryCompiler;
52 34
        $this->parameterManager = $parameterManager;
53 34
    }
54
55
    /**
56
     * @return BuilderInterface
57
     */
58 34
    public function getQueryBuilder()
59
    {
60 34
        return $this;
61
    }
62
63
    /**
64
     * @return TableFactoryInterface
65
     */
66 32
    public function getTableFactory()
67
    {
68 32
        return $this->tableFactory;
69
    }
70
71
    /**
72
     * @return QueryCompilerInterface
73
     */
74 34
    public function getQueryCompiler()
75
    {
76 34
        return $this->queryCompiler;
77
    }
78
79
    /**
80
     * @return ParameterManagerInterface
81
     */
82 34
    public function getParameterManager()
83
    {
84 34
        return $this->parameterManager;
85
    }
86
87
    /**
88
     * @inheritdoc
89
     */
90 34
    public function buildSQL()
91
    {
92 34
        return $this->getQueryCompiler()->compile($this->getQueryBuilder());
93
    }
94
95
    /**
96
     * @inheritdoc
97
     */
98 22
    public function objectToString($object)
99
    {
100 22
        return $this->getParameterManager()->createReference($object);
101
    }
102
103
    /**
104
     * @param ConnectionInterface $connection
0 ignored issues
show
Documentation introduced by
Should the type for parameter $connection not be null|ConnectionInterface?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
105
     *
106
     * @return Query
107
     */
108 13
    public function buildQuery(ConnectionInterface $connection = null)
109
    {
110 13
        return new Query(
111 13
            $this->buildSQL(),
112 13
            $this->getParameterManager(),
113
            $connection
114 13
        );
115
    }
116
}