Issues (493)

lib/SP/Storage/Database/QueryResult.php (3 issues)

1
<?php
2
/**
3
 * sysPass
4
 *
5
 * @author    nuxsmin
6
 * @link      https://syspass.org
7
 * @copyright 2012-2019, Rubén Domínguez nuxsmin@$syspass.org
8
 *
9
 * This file is part of sysPass.
10
 *
11
 * sysPass is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation, either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * sysPass is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 *  along with sysPass.  If not, see <http://www.gnu.org/licenses/>.
23
 */
24
25
namespace SP\Storage\Database;
26
27
/**
28
 * Class QueryResult
29
 *
30
 * @package SP\Storage\Database
31
 */
32
final class QueryResult
33
{
34
    /**
35
     * @var array
36
     */
37
    private $data;
38
    /**
39
     * @var int
40
     */
41
    private $numRows = 0;
42
    /**
43
     * @var int
44
     */
45
    private $totalNumRows;
46
    /**
47
     * @var int
48
     */
49
    private $affectedNumRows;
50
    /**
51
     * @var int
52
     */
53
    private $statusCode;
54
    /**
55
     * @var int
56
     */
57
    private $lastId = 0;
58
59
    /**
60
     * QueryResult constructor.
61
     *
62
     * @param array $data
63
     */
64
    public function __construct(array $data = null)
65
    {
66
        if ($data !== null) {
67
            $this->data = $data;
68
            $this->numRows = count($data);
69
        }
70
    }
71
72
    /**
73
     * @param array $data
74
     * @param null  $totalNumRows
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $totalNumRows is correct as it would always require null to be passed?
Loading history...
75
     *
76
     * @return QueryResult
77
     */
78
    public static function fromResults(array $data, $totalNumRows = null)
79
    {
80
        $result = new self($data);
81
82
        if ($totalNumRows !== null) {
0 ignored issues
show
The condition $totalNumRows !== null is always false.
Loading history...
83
            $result->totalNumRows = $totalNumRows;
84
        }
85
86
        return $result;
87
    }
88
89
    /**
90
     * @param string $class
91
     *
92
     * @return mixed|null
93
     */
94
    public function getData(string $class = null)
0 ignored issues
show
The parameter $class is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

94
    public function getData(/** @scrutinizer ignore-unused */ string $class = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
95
    {
96
        if ($this->numRows === 1) {
97
            return $this->data[0];
98
        }
99
100
        return null;
101
    }
102
103
    /**
104
     * Always returns an array
105
     *
106
     * @return array
107
     */
108
    public function getDataAsArray(): array
109
    {
110
        return (array)$this->data;
111
    }
112
113
    /**
114
     * @return int
115
     */
116
    public function getNumRows(): int
117
    {
118
        return $this->numRows;
119
    }
120
121
    /**
122
     * @return int
123
     */
124
    public function getTotalNumRows(): int
125
    {
126
        return $this->totalNumRows;
127
    }
128
129
    /**
130
     * @param int $totalNumRows
131
     *
132
     * @return QueryResult
133
     */
134
    public function setTotalNumRows(int $totalNumRows)
135
    {
136
        $this->totalNumRows = $totalNumRows;
137
138
        return $this;
139
    }
140
141
    /**
142
     * @return int
143
     */
144
    public function getStatusCode(): int
145
    {
146
        return $this->statusCode;
147
    }
148
149
    /**
150
     * @param int $statusCode
151
     *
152
     * @return QueryResult
153
     */
154
    public function setStatusCode(int $statusCode)
155
    {
156
        $this->statusCode = $statusCode;
157
158
        return $this;
159
    }
160
161
    /**
162
     * @return int
163
     */
164
    public function getAffectedNumRows(): int
165
    {
166
        return $this->affectedNumRows;
167
    }
168
169
    /**
170
     * @param int $affectedNumRows
171
     *
172
     * @return QueryResult
173
     */
174
    public function setAffectedNumRows(int $affectedNumRows)
175
    {
176
        $this->affectedNumRows = $affectedNumRows;
177
178
        return $this;
179
    }
180
181
    /**
182
     * @return int
183
     */
184
    public function getLastId(): int
185
    {
186
        return $this->lastId;
187
    }
188
189
    /**
190
     * @param int $lastId
191
     *
192
     * @return QueryResult
193
     */
194
    public function setLastId(int $lastId)
195
    {
196
        $this->lastId = $lastId;
197
198
        return $this;
199
    }
200
}