1 | <?php |
||
7 | class Common |
||
8 | { |
||
9 | /** |
||
10 | * @const ERR_EXECUTE_BAD_REQUEST Exception code if a request has fail |
||
11 | * during execution |
||
12 | */ |
||
13 | const ERR_EXECUTE_BAD_REQUEST = 2201001; |
||
14 | |||
15 | /** |
||
16 | * @const ERR_EXECUTED_UNKNOWN_ERROR Exception code if a request has fail |
||
17 | * but when the error has not been returned by PDO::errorInfos() |
||
18 | */ |
||
19 | const ERR_EXECUTED_UNKNOWN_ERROR = 2201002; |
||
20 | |||
21 | /** |
||
22 | * @var \BfwSql\Queries\AbstractQuery $query Query system object |
||
23 | */ |
||
24 | protected $query; |
||
25 | |||
26 | /** |
||
27 | * @var \BfwSql\SqlConnect $sqlConnect SqlConnect object |
||
28 | */ |
||
29 | protected $sqlConnect; |
||
30 | |||
31 | /** |
||
32 | * @var boolean $isPreparedRequest If is a prepared request |
||
33 | */ |
||
34 | protected $isPreparedRequest = true; |
||
35 | |||
36 | /** |
||
37 | * @var array $lastErrorInfos The PDO::errorInfos return for the last |
||
38 | * query executed. Empty if no request has been executed. |
||
39 | */ |
||
40 | protected $lastErrorInfos = []; |
||
41 | |||
42 | /** |
||
43 | * @var \PDOStatement $lastRequestStatement The PDOStatement pour the |
||
44 | * last request executed. |
||
45 | */ |
||
46 | protected $lastRequestStatement; |
||
47 | |||
48 | /** |
||
49 | * @var boolean $noResult If request has sent no result. |
||
50 | */ |
||
51 | protected $noResult = false; |
||
52 | |||
53 | /** |
||
54 | * @var array $prepareDriversOptions SGBD driver option used for |
||
55 | * prepared request |
||
56 | * |
||
57 | * @link http://php.net/manual/en/pdo.prepare.php |
||
58 | */ |
||
59 | protected $prepareDriversOptions = array(); |
||
60 | |||
61 | /** |
||
62 | * Constructor |
||
63 | * |
||
64 | * @param \BfwSql\Queries\AbstractQuery $query Instance of query |
||
65 | * system |
||
66 | */ |
||
67 | public function __construct(\BfwSql\Queries\AbstractQuery $query) |
||
72 | |||
73 | /** |
||
74 | * Getter to access to isPreparedRequest property |
||
75 | * |
||
76 | * @return boolean |
||
77 | */ |
||
78 | public function getIsPreparedRequest(): bool |
||
82 | |||
83 | /** |
||
84 | * Setter to enable or disable prepared request |
||
85 | * |
||
86 | * @param boolean $preparedRequestStatus The new status for prepared request |
||
87 | * |
||
88 | * @return $this |
||
89 | */ |
||
90 | public function setIsPreparedRequest(bool $preparedRequestStatus): self |
||
96 | |||
97 | /** |
||
98 | * Getter to access to lastErrorInfos property |
||
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | public function getLastErrorInfos(): array |
||
106 | |||
107 | /** |
||
108 | * Getter to access to lastRequestStatement property |
||
109 | * |
||
110 | * @return \PDOStatement|null |
||
111 | */ |
||
112 | public function getLastRequestStatement() |
||
116 | |||
117 | /** |
||
118 | * Getter to access to noResult property |
||
119 | * |
||
120 | * @return boolean |
||
121 | */ |
||
122 | public function getNoResult(): bool |
||
126 | |||
127 | /** |
||
128 | * Getter to access at prepareDriversOptions property |
||
129 | * |
||
130 | * @return array |
||
131 | */ |
||
132 | public function getPrepareDriversOptions(): array |
||
136 | |||
137 | /** |
||
138 | * Define driver options to prepared request |
||
139 | * |
||
140 | * @link http://php.net/manual/fr/pdo.prepare.php |
||
141 | * |
||
142 | * @param array $driverOptions Drivers options |
||
143 | * |
||
144 | * @return $this |
||
145 | */ |
||
146 | public function setPrepareDriversOptions(array $driverOptions): self |
||
152 | |||
153 | /** |
||
154 | * Getter accessor to property query |
||
155 | * |
||
156 | * @return \BfwSql\Queries\AbstractQuery |
||
157 | */ |
||
158 | public function getQuery(): \BfwSql\Queries\AbstractQuery |
||
162 | |||
163 | /** |
||
164 | * Getter to access at sqlConnect property |
||
165 | * |
||
166 | * @return \BfwSql\SqlConnect |
||
167 | */ |
||
168 | public function getSqlConnect(): \BfwSql\SqlConnect |
||
172 | |||
173 | /** |
||
174 | * Execute the assembled request |
||
175 | * |
||
176 | * @return array The pdo errorInfo array |
||
177 | */ |
||
178 | protected function executeQuery(): array |
||
197 | |||
198 | /** |
||
199 | * Execute a prepared request |
||
200 | * |
||
201 | * @return \PDOStatement |
||
202 | */ |
||
203 | protected function executePreparedQuery(): \PDOStatement |
||
215 | |||
216 | /** |
||
217 | * Execute a not prepared request |
||
218 | * |
||
219 | * @return \PDOStatement|integer |
||
220 | */ |
||
221 | protected function executeNotPreparedQuery() |
||
231 | |||
232 | /** |
||
233 | * Execute the assembled request and check if there are errors |
||
234 | * Update property noResult |
||
235 | * |
||
236 | * @throws \Exception If the request fail |
||
237 | * |
||
238 | * @return \PDOStatement|integer |
||
239 | */ |
||
240 | public function execute() |
||
266 | |||
267 | /** |
||
268 | * Closes the cursor, enabling the statement to be executed again. |
||
269 | * |
||
270 | * @link http://php.net/manual/fr/pdostatement.closecursor.php |
||
271 | * |
||
272 | * @return void |
||
273 | */ |
||
274 | public function closeCursor() |
||
278 | |||
279 | /** |
||
280 | * Return the number of impacted rows by the last request |
||
281 | * |
||
282 | * @return int|bool |
||
283 | */ |
||
284 | public function obtainImpactedRows() |
||
297 | |||
298 | /** |
||
299 | * Send a notify to application observers |
||
300 | * |
||
301 | * @return void |
||
302 | */ |
||
303 | protected function callObserver() |
||
309 | } |
||
310 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.