Test Setup Failed
Branch master (10fdc5)
by Beniamin
35:44
created

Query   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 109
c 0
b 0
f 0
wmc 10
lcom 1
cbo 3
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getSQL() 0 4 1
A fetchScalar() 0 4 1
A fetchRow() 0 4 1
A fetchAll() 0 4 1
A rowCount() 0 4 1
A execute() 0 4 1
A getParameterCollection() 0 4 1
A setParameter() 0 6 1
A getConnection() 0 4 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
    public function __construct(
43
        $sql,
44
        ParameterCollectionInterface $parameterCollection,
45
        ConnectionInterface $connection
46
    ) {
47
        $this->sql = $sql;
48
        $this->parameterCollection = $parameterCollection;
49
        $this->connection = $connection;
50
    }
51
52
    /**
53
     * @return string
54
     */
55
    public function getSQL()
56
    {
57
        return $this->sql;
58
    }
59
60
    /**
61
     * @return mixed
62
     */
63
    public function fetchScalar()
64
    {
65
        return $this->connection->fetchScalar($this->sql, $this->parameterCollection->toArray());
66
    }
67
68
    /**
69
     * @return array
70
     */
71
    public function fetchRow()
72
    {
73
        return $this->connection->fetchRow($this->sql, $this->parameterCollection->toArray());
74
    }
75
76
    /**
77
     * @return array
78
     */
79
    public function fetchAll()
80
    {
81
        return $this->connection->fetchAll($this->sql, $this->parameterCollection->toArray());
82
    }
83
84
    /**
85
     * @return int
86
     */
87
    public function rowCount()
88
    {
89
        return $this->connection->rowCount($this->sql, $this->parameterCollection->toArray());
90
    }
91
92
    /**
93
     * @return int
94
     */
95
    public function execute()
96
    {
97
        return $this->connection->execute($this->sql, $this->parameterCollection->toArray());
98
    }
99
100
    /**
101
     * @return ParameterCollectionInterface
102
     */
103
    public function getParameterCollection()
104
    {
105
        return $this->parameterCollection;
106
    }
107
108
    /**
109
     * @param int|string $name
110
     * @param mixed      $value
111
     *
112
     * @return $this
113
     */
114
    public function setParameter($name, $value)
115
    {
116
        $this->getParameterCollection()->getParameter($name)->setValue($value);
117
118
        return $this;
119
    }
120
121
    /**
122
     * @return ConnectionInterface
123
     */
124
    public function getConnection()
125
    {
126
        return $this->connection;
127
    }
128
}