Completed
Push — master ( 77e4e4...2e1347 )
by Beniamin
05:23
created

Query::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 10
Bugs 0 Features 8
Metric Value
c 10
b 0
f 8
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 1
eloc 7
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Phuria\QueryBuilder;
4
5
use Phuria\QueryBuilder\Connection\ConnectionInterface;
6
use Phuria\QueryBuilder\Parameter\ParameterManagerInterface;
7
8
/**
9
 * @author Beniamin Jonatan Šimko <[email protected]>
10
 */
11
class Query
12
{
13
    /**
14
     * @var string $sql
15
     */
16
    private $sql;
17
18
    /**
19
     * @var ParameterManagerInterface $parameterManager
20
     */
21
    private $parameterManager;
22
23
    /**
24
     * @var ConnectionInterface $connection
25
     */
26
    private $connection;
27
28
    /**
29
     * @param string                    $sql
30
     * @param ParameterManagerInterface $parameterManager
31
     * @param ConnectionInterface       $connection
32
     */
33 11
    public function __construct(
34
        $sql,
35
        ParameterManagerInterface $parameterManager,
36
        ConnectionInterface $connection = null
37
    ) {
38 11
        $this->sql = $sql;
39 11
        $this->parameterManager = $parameterManager;
40 11
        $this->connection = $connection;
41 11
    }
42
43
    /**
44
     * @return string
45
     */
46 10
    public function getSQL()
47
    {
48 10
        return $this->sql;
49
    }
50
51
    /**
52
     * @return mixed
53
     */
54 1
    public function fetchScalar()
55
    {
56 1
        $stmt = $this->connection->prepare($this->sql);
57 1
        $this->parameterManager->bindStatement($stmt);
58 1
        $stmt->execute();
59
60 1
        return $stmt->fetchScalar();
61
    }
62
}