Completed
Push — master ( 4d03e2...c94c1b )
by Beniamin
02:43 queued 13s
created

Query   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 66
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getSQL() 0 4 1
A getParameters() 0 4 1
A setParameter() 0 6 1
A prepareStatement() 0 4 1
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\Query;
13
14
use Phuria\UnderQuery\Connection\ConnectionInterface;
15
use Phuria\UnderQuery\Parameter\ParameterCollection;
16
use Phuria\UnderQuery\Parameter\ParameterCollectionInterface;
17
use Phuria\UnderQuery\Statement\StatementInterface;
18
19
/**
20
 * @author Beniamin Jonatan Šimko <[email protected]>
21
 */
22
class Query implements QueryInterface
23
{
24
    /**
25
     * @var string
26
     */
27
    private $compiledSQL;
28
29
    /**
30
     * @var ParameterCollectionInterface
31
     */
32
    private $parameterCollection;
33
34
    /**
35
     * @var ConnectionInterface|null
36
     */
37
    private $connection;
38
39
    /**
40
     * @param string                   $compiledSQL
41
     * @param array                    $parameters
42
     * @param ConnectionInterface|null $connection
43
     */
44 3
    public function __construct($compiledSQL, array $parameters = [], ConnectionInterface $connection = null)
45
    {
46 3
        $this->compiledSQL = $compiledSQL;
47 3
        $this->parameterCollection = new ParameterCollection($parameters);
48 3
        $this->connection = $connection;
49 3
    }
50
51
    /**
52
     * @return string
53
     */
54 1
    public function getSQL()
55
    {
56 1
        return $this->compiledSQL;
57
    }
58
59
    /**
60
     * @return ParameterCollectionInterface
61
     */
62 2
    public function getParameters()
63
    {
64 2
        return $this->parameterCollection;
65
    }
66
67
    /**
68
     * @param int|string $name
69
     * @param mixed      $value
70
     *
71
     * @return $this
72
     */
73 1
    public function setParameter($name, $value)
74
    {
75 1
        $this->getParameters()->setValue($name, $value);
76
77 1
        return $this;
78
    }
79
80
    /**
81
     * @return StatementInterface
82
     */
83
    public function prepareStatement()
84
    {
85
        return $this->connection->prepareStatement($this->getSQL(), $this->getParameters()->toArray());
86
    }
87
}