Passed
Branch master (10fdc5)
by Beniamin
02:43
created

Query::fetchScalar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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\UnderQuery\Query;
13
14
use Phuria\UnderQuery\Connection\ConnectionInterface;
15
use Phuria\UnderQuery\Parameter\ParameterCollectionInterface;
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 ParameterCollectionInterface
29
     */
30
    private $parameterCollection;
31
32
    /**
33
     * @var ConnectionInterface
34
     */
35
    private $connection;
36
37
    /**
38
     * @param string                       $sql
39
     * @param ParameterCollectionInterface $parameterCollection
40
     * @param ConnectionInterface          $connection
41
     */
42 4
    public function __construct(
43
        $sql,
44
        ParameterCollectionInterface $parameterCollection,
45
        ConnectionInterface $connection
46
    ) {
47 4
        $this->sql = $sql;
48 4
        $this->parameterCollection = $parameterCollection;
49 4
        $this->connection = $connection;
50 4
    }
51
52
    /**
53
     * @return string
54
     */
55 1
    public function getSQL()
56
    {
57 1
        return $this->sql;
58
    }
59
60
    /**
61
     * @return mixed
62
     */
63 2
    public function fetchScalar()
64
    {
65 2
        return $this->connection->fetchScalar($this->sql, $this->parameterCollection->toArray());
66
    }
67
68
    /**
69
     * @return array
70
     */
71 1
    public function fetchRow()
72
    {
73 1
        return $this->connection->fetchRow($this->sql, $this->parameterCollection->toArray());
74
    }
75
76
    /**
77
     * @return array
78
     */
79 1
    public function fetchAll()
80
    {
81 1
        return $this->connection->fetchAll($this->sql, $this->parameterCollection->toArray());
82
    }
83
84
    /**
85
     * @return int
86
     */
87 1
    public function rowCount()
88
    {
89 1
        return $this->connection->rowCount($this->sql, $this->parameterCollection->toArray());
90
    }
91
92
    /**
93
     * @return int
94
     */
95 1
    public function execute()
96
    {
97 1
        return $this->connection->execute($this->sql, $this->parameterCollection->toArray());
98
    }
99
100
    /**
101
     * @return ParameterCollectionInterface
102
     */
103 2
    public function getParameterCollection()
104
    {
105 2
        return $this->parameterCollection;
106
    }
107
108
    /**
109
     * @param int|string $name
110
     * @param mixed      $value
111
     *
112
     * @return $this
113
     */
114 1
    public function setParameter($name, $value)
115
    {
116 1
        $this->getParameterCollection()->getParameter($name)->setValue($value);
117
118 1
        return $this;
119
    }
120
121
    /**
122
     * @return ConnectionInterface
123
     */
124 1
    public function getConnection()
125
    {
126 1
        return $this->connection;
127
    }
128
}