1 | <?php |
||
46 | abstract class Row implements RowInterface, \JsonSerializable, \ArrayAccess |
||
47 | { |
||
48 | use Container\Container; |
||
49 | use Container\ArrayAccess; |
||
50 | use Container\JsonSerialize; |
||
51 | use Container\MagicAccess; |
||
52 | use Traits\TableProperty; |
||
53 | use Traits\RowRelations; |
||
54 | |||
55 | /** |
||
56 | * @var Table instance of Table class |
||
57 | */ |
||
58 | protected $table; |
||
59 | |||
60 | /** |
||
61 | * This is set to a copy of $data when the data is fetched from |
||
62 | * a database, specified as a new tuple in the constructor, or |
||
63 | * when dirty data is posted to the database with save(). |
||
64 | * |
||
65 | * @var array |
||
66 | */ |
||
67 | protected $clean = []; |
||
68 | |||
69 | /** |
||
70 | * Create Row instance |
||
71 | * |
||
72 | * @param array $data |
||
73 | */ |
||
74 | 17 | public function __construct(array $data = []) |
|
85 | |||
86 | /** |
||
87 | * List of required for serialization properties |
||
88 | * |
||
89 | * @return string[] |
||
90 | */ |
||
91 | public function __sleep() |
||
95 | |||
96 | /** |
||
97 | * Cast to string as class name |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | public function __toString() |
||
105 | |||
106 | /** |
||
107 | * Magic method for var_dump() |
||
108 | * |
||
109 | * @return array |
||
110 | * @see var_dump() |
||
111 | */ |
||
112 | public function __debugInfo() |
||
120 | |||
121 | /** |
||
122 | * Validate input data |
||
123 | * |
||
124 | * @param array $data |
||
125 | * |
||
126 | * @return bool |
||
127 | */ |
||
128 | public function validate($data) : bool |
||
132 | |||
133 | /** |
||
134 | * Assert input data |
||
135 | * |
||
136 | * @param array $data |
||
137 | * |
||
138 | * @return void |
||
139 | */ |
||
140 | public function assert($data) : void |
||
144 | |||
145 | /** |
||
146 | * Saves the properties to the database. |
||
147 | * |
||
148 | * This performs an intelligent insert/update, and reloads the |
||
149 | * properties with fresh data from the table on success. |
||
150 | * |
||
151 | * @return mixed The primary key value(s), as an associative array if the |
||
152 | * key is compound, or a scalar if the key is single-column |
||
153 | * @throws DbException |
||
154 | * @throws InvalidPrimaryKeyException |
||
155 | * @throws TableNotFoundException |
||
156 | * @throws \Bluz\Common\Exception\ConfigurationException |
||
157 | */ |
||
158 | 2 | public function save() |
|
176 | |||
177 | /** |
||
178 | * Insert row to Db |
||
179 | * |
||
180 | * @return mixed The primary key value(s), as an associative array if the |
||
181 | * key is compound, or a scalar if the key is single-column |
||
182 | * @throws InvalidPrimaryKeyException |
||
183 | * @throws TableNotFoundException |
||
184 | */ |
||
185 | 1 | protected function doInsert() |
|
232 | |||
233 | /** |
||
234 | * Update row |
||
235 | * |
||
236 | * @return integer The number of rows updated |
||
237 | * @throws InvalidPrimaryKeyException |
||
238 | * @throws TableNotFoundException |
||
239 | */ |
||
240 | 1 | protected function doUpdate() : int |
|
293 | |||
294 | /** |
||
295 | * Delete existing row |
||
296 | * |
||
297 | * @return bool Removed or not |
||
298 | * @throws InvalidPrimaryKeyException |
||
299 | * @throws TableNotFoundException |
||
300 | */ |
||
301 | 1 | public function delete() : bool |
|
328 | |||
329 | /** |
||
330 | * Retrieves an associative array of primary keys, if it exists |
||
331 | * |
||
332 | * @return array |
||
333 | * @throws InvalidPrimaryKeyException |
||
334 | * @throws TableNotFoundException |
||
335 | */ |
||
336 | 3 | protected function getPrimaryKey() : array |
|
342 | |||
343 | /** |
||
344 | * Refreshes properties from the database |
||
345 | * |
||
346 | * @return void |
||
347 | */ |
||
348 | public function refresh() : void |
||
353 | |||
354 | /** |
||
355 | * After read data from Db |
||
356 | * |
||
357 | * @return void |
||
358 | */ |
||
359 | 17 | protected function afterRead() : void |
|
362 | |||
363 | /** |
||
364 | * Allows pre-insert and pre-update logic to be applied to row. |
||
365 | * Subclasses may override this method |
||
366 | * |
||
367 | * @return void |
||
368 | */ |
||
369 | protected function beforeSave() : void |
||
372 | |||
373 | /** |
||
374 | * Allows post-insert and post-update logic to be applied to row. |
||
375 | * Subclasses may override this method |
||
376 | * |
||
377 | * @return void |
||
378 | */ |
||
379 | 2 | protected function afterSave() : void |
|
382 | |||
383 | /** |
||
384 | * Allows pre-insert logic to be applied to row. |
||
385 | * Subclasses may override this method |
||
386 | * |
||
387 | * @return void |
||
388 | */ |
||
389 | 1 | protected function beforeInsert() : void |
|
392 | |||
393 | /** |
||
394 | * Allows post-insert logic to be applied to row. |
||
395 | * Subclasses may override this method |
||
396 | * |
||
397 | * @return void |
||
398 | */ |
||
399 | 1 | protected function afterInsert() : void |
|
402 | |||
403 | /** |
||
404 | * Allows pre-update logic to be applied to row. |
||
405 | * Subclasses may override this method |
||
406 | * |
||
407 | * @return void |
||
408 | */ |
||
409 | 1 | protected function beforeUpdate() : void |
|
412 | |||
413 | /** |
||
414 | * Allows post-update logic to be applied to row. |
||
415 | * Subclasses may override this method |
||
416 | * |
||
417 | * @return void |
||
418 | */ |
||
419 | 1 | protected function afterUpdate() : void |
|
422 | |||
423 | /** |
||
424 | * Allows pre-delete logic to be applied to row. |
||
425 | * Subclasses may override this method |
||
426 | * |
||
427 | * @return void |
||
428 | */ |
||
429 | 1 | protected function beforeDelete() : void |
|
432 | |||
433 | /** |
||
434 | * Allows post-delete logic to be applied to row. |
||
435 | * Subclasses may override this method |
||
436 | * |
||
437 | * @return void |
||
438 | */ |
||
439 | 1 | protected function afterDelete() : void |
|
442 | } |
||
443 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()
method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail()
, this method _has_ side-effects. In the following case, we could not remove the method call: