1 | <?php |
||
17 | abstract class DataBaseModel implements DataBaseModelInterface |
||
18 | { |
||
19 | protected $tableName; |
||
20 | protected $dbConn; |
||
21 | protected $dataBaseQuery; |
||
22 | protected $properties; |
||
23 | protected $arrayField; |
||
24 | |||
25 | /** |
||
26 | * This is a constructor; a default method that will be called automatically during class instantiation. |
||
27 | */ |
||
28 | 42 | public function __construct($dbConn) |
|
29 | { |
||
30 | 42 | $this->tableName = self::getClassName(); |
|
31 | 3 | $this->dataBaseQuery = new DataBaseQuery($dbConn); |
|
32 | $this->arrayField['id'] = 0; |
||
33 | 42 | } |
|
34 | |||
35 | 42 | /** |
|
36 | 42 | * The magic setter method. |
|
37 | 42 | * |
|
38 | * @param $properties |
||
39 | * @param $values |
||
40 | * |
||
41 | * @return array associative array properties |
||
42 | */ |
||
43 | public function __set($properties, $values) |
||
47 | 42 | ||
48 | /** |
||
49 | 42 | * The magic getter method. |
|
50 | 42 | * |
|
51 | * @param $properties |
||
52 | * |
||
53 | * @return array key |
||
54 | */ |
||
55 | public function __get($properties) |
||
59 | |||
60 | /** |
||
61 | * This method gets all the record from a particular table |
||
62 | * by accessing the read method from the DataBaseQuery class. |
||
63 | * |
||
64 | * |
||
65 | * @return associative array |
||
66 | */ |
||
67 | public static function getAll($dbConn) |
||
78 | |||
79 | public static function throwNoDataFoundException() |
||
84 | |||
85 | /** |
||
86 | * This method either create or update record in a database table |
||
87 | * by calling either the read method or create method in the |
||
88 | * DataBaseQuery class. |
||
89 | * |
||
90 | 2 | * @throws NoRecordUpdateException |
|
91 | * @throws EmptyArrayException |
||
92 | * @throws NoRecordCreatedException |
||
93 | * |
||
94 | * @return bool true or false; |
||
95 | */ |
||
96 | public function save($dbConn) |
||
124 | |||
125 | public function throwNoRecordUpdatedException() |
||
130 | |||
131 | 9 | public function throwEmptyArrayException() |
|
136 | |||
137 | 6 | public function throwNoRecordCreatedException() |
|
142 | |||
143 | /** |
||
144 | * This method find a record by id. |
||
145 | * |
||
146 | * @param $id |
||
147 | * |
||
148 | * @throws ArgumentNumberIncorrectException |
||
149 | * @throws ArgumentNotFoundException |
||
150 | * |
||
151 | * @return object |
||
152 | */ |
||
153 | public static function findById($id) |
||
171 | |||
172 | /** |
||
173 | * This method find a record by id and returns |
||
174 | 9 | * all the data present in the id. |
|
175 | * |
||
176 | 9 | * |
|
177 | 9 | * @return associative array |
|
178 | 3 | */ |
|
179 | public function getById() |
||
187 | 3 | ||
188 | /** |
||
189 | * This method delete a row from the table by the row id. |
||
190 | 42 | * |
|
191 | * @param $id |
||
192 | 42 | * |
|
193 | * @throws ArgumentNumberIncorrectException; |
||
194 | 42 | * @throws ArgumentNotFoundException; |
|
195 | * |
||
196 | * @return bool true |
||
197 | */ |
||
198 | public static function destroy($id, $dbConn) |
||
213 | |||
214 | public static function getClassName() |
||
220 | |||
221 | /** |
||
222 | * This method check if the argument passed to this function is an array. |
||
223 | * |
||
224 | * @param $arrayOfRecord |
||
225 | * |
||
226 | * @return bool true |
||
227 | */ |
||
228 | public function checkIfRecordIsEmpty($arrayOfRecord) |
||
236 | } |
||
237 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.