Completed
Push — master ( be00fa...152a7c )
by Beniamin
05:51 queued 02:08
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 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 3
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\Query;
13
14
use Phuria\SQLBuilder\Connection\ConnectionInterface;
15
use Phuria\SQLBuilder\Parameter\ParameterManagerInterface;
16
17
/**
18
 * @author Beniamin Jonatan Šimko <[email protected]>
19
 */
20
class Query
21
{
22
    /**
23
     * @var string
24
     */
25
    private $sql;
26
27
    /**
28
     * @var ParameterManagerInterface
29
     */
30
    private $parameterManager;
31
32
    /**
33
     * @var ConnectionInterface
34
     */
35
    private $connection;
36
37
    /**
38
     * @param string                    $sql
39
     * @param ParameterManagerInterface $parameterManager
40
     * @param ConnectionInterface       $connection
41
     */
42 1
    public function __construct(
43
        $sql,
44
        ParameterManagerInterface $parameterManager,
45
        ConnectionInterface $connection
46
    ) {
47 1
        $this->sql = $sql;
48 1
        $this->parameterManager = $parameterManager;
49 1
        $this->connection = $connection;
50 1
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getSQL()
56
    {
57
        return $this->sql;
58
    }
59
60
    /**
61
     * @return mixed
62
     */
63 1
    public function fetchScalar()
64
    {
65 1
        return $this->connection->fetchScalar($this->sql, $this->parameterManager->toArray());
66
    }
67
68
    /**
69
     * @return array
70
     */
71
    public function fetchRow()
72
    {
73
        return $this->connection->fetchRow($this->sql, $this->parameterManager->toArray());
74
    }
75
76
    /**
77
     * @return array
78
     */
79
    public function fetchAll()
80
    {
81
        return $this->connection->fetchAll($this->sql, $this->parameterManager->toArray());
82
    }
83
84
    /**
85
     * @return int
86
     */
87
    public function rowCount()
88
    {
89
        return $this->connection->rowCount($this->sql, $this->parameterManager->toArray());
90
    }
91
92
    /**
93
     * @param int|string $name
94
     * @param mixed      $value
95
     *
96
     * @return $this
97
     */
98
    public function setParameter($name, $value)
99
    {
100
        $this->parameterManager->createOrGetParameter($name)->setValue($value);
101
102
        return $this;
103
    }
104
105
    /**
106
     * @return ParameterManagerInterface
107
     */
108
    public function getParameterManager()
109
    {
110
        return $this->parameterManager;
111
    }
112
113
    /**
114
     * @return ConnectionInterface
115
     */
116
    public function getConnection()
117
    {
118
        return $this->connection;
119
    }
120
}