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 | * @throws NoDataFoundException |
||
65 | * |
||
66 | * @return associative array |
||
67 | */ |
||
68 | public static function getAll($dbConn) |
||
74 | 6 | ||
75 | /** |
||
76 | 3 | * This method either create or update record in a database table |
|
77 | * by calling either the read method or create method in the |
||
78 | * DataBaseQuery class. |
||
79 | * |
||
80 | * @throws NoRecordUpdateException |
||
81 | * @throws EmptyArrayException |
||
82 | * @throws NoRecordCreatedException |
||
83 | * |
||
84 | * @return bool true or false; |
||
85 | */ |
||
86 | public function save($dbConn) |
||
116 | |||
117 | public function throwNoRecordUpdatedException() |
||
122 | |||
123 | /** |
||
124 | * This method find a record by id. |
||
125 | * |
||
126 | * @param $id |
||
127 | * |
||
128 | * @throws ArgumentNumberIncorrectException |
||
129 | 9 | * @throws ArgumentNotFoundException |
|
130 | * |
||
131 | 9 | * @return object |
|
132 | */ |
||
133 | 9 | public static function findById($id) |
|
151 | |||
152 | /** |
||
153 | * This method find a record by id and returns |
||
154 | * all the data present in the id. |
||
155 | * |
||
156 | * |
||
157 | * @return associative array |
||
158 | */ |
||
159 | public function getById() |
||
167 | |||
168 | /** |
||
169 | * This method delete a row from the table by the row id. |
||
170 | * |
||
171 | * @param $id |
||
172 | * |
||
173 | * @throws ArgumentNumberIncorrectException; |
||
174 | 9 | * @throws ArgumentNotFoundException; |
|
175 | * |
||
176 | 9 | * @return bool true |
|
177 | 9 | */ |
|
178 | 3 | public static function destroy($id, $dbConn) |
|
193 | |||
194 | 42 | public static function getClassName() |
|
200 | |||
201 | /** |
||
202 | * This method check if the argument passed to this function is an array. |
||
203 | * |
||
204 | 6 | * @param $arrayOfRecord |
|
205 | * |
||
206 | 6 | * @return bool true |
|
207 | 3 | */ |
|
208 | public function checkIfRecordIsEmpty($arrayOfRecord) |
||
216 | } |
||
217 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.