Complex classes like FluentPdoModel often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use FluentPdoModel, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
37 | class FluentPdoModel |
||
38 | { |
||
39 | const OPERATOR_AND = ' AND '; |
||
40 | const OPERATOR_OR = ' OR '; |
||
41 | const ORDERBY_ASC = 'ASC'; |
||
42 | const ORDERBY_DESC = 'DESC'; |
||
43 | const SAVE_INSERT = 'INSERT'; |
||
44 | const SAVE_UPDATE = 'UPDATE'; |
||
45 | const LEFT_JOIN = 'LEFT'; |
||
46 | const INNER_JOIN = 'INNER'; |
||
47 | const ONE_DAY = 86400; |
||
48 | const ONE_WEEK = 60480060; |
||
49 | const ONE_HOUR = 3600; |
||
50 | const TEN_MINS = 600; |
||
51 | const CACHE_NO = -1; |
||
52 | const CACHE_DEFAULT = 0; |
||
53 | |||
54 | /** @var AbstractPdo $_connection */ |
||
55 | protected $_connection = null; |
||
56 | |||
57 | /** @var string */ |
||
58 | protected $_primary_key = 'id'; |
||
59 | |||
60 | /** @var array */ |
||
61 | protected $_where_parameters = []; |
||
62 | |||
63 | /** @var array */ |
||
64 | protected $_select_fields = []; |
||
65 | |||
66 | /** @var array */ |
||
67 | protected $_join_sources = []; |
||
68 | |||
69 | /** @var array */ |
||
70 | protected $_join_aliases = []; |
||
71 | |||
72 | /** @var array $_associations */ |
||
73 | protected $_associations = [ |
||
74 | 'belongsTo' => [], |
||
75 | ]; |
||
76 | |||
77 | /** @var array */ |
||
78 | protected $_where_conditions = []; |
||
79 | |||
80 | protected $_raw_sql = null; |
||
81 | |||
82 | /** @var int */ |
||
83 | protected $_limit = null; |
||
84 | |||
85 | /** @var int */ |
||
86 | protected $_offset = null; |
||
87 | |||
88 | /** @var array */ |
||
89 | protected $_order_by = []; |
||
90 | |||
91 | /** @var array */ |
||
92 | protected $_group_by = []; |
||
93 | |||
94 | /** @var string */ |
||
95 | protected $_and_or_operator = self::OPERATOR_AND; |
||
96 | |||
97 | /** @var array */ |
||
98 | protected $_having = []; |
||
99 | |||
100 | /** @var bool */ |
||
101 | protected $_wrap_open = false; |
||
102 | |||
103 | /** @var int */ |
||
104 | protected $_last_wrap_position = 0; |
||
105 | |||
106 | /** @var PDOStatement $_pdo_stmt */ |
||
107 | protected $_pdo_stmt = null; |
||
108 | |||
109 | /** @var bool */ |
||
110 | protected $_distinct = false; |
||
111 | |||
112 | /** @var null */ |
||
113 | protected $_requested_fields = []; |
||
114 | |||
115 | /** @var null */ |
||
116 | protected $_filter_meta = []; |
||
117 | |||
118 | /** @var bool */ |
||
119 | protected $_log_queries = false; |
||
120 | |||
121 | /** @var array */ |
||
122 | protected $_timer = []; |
||
123 | |||
124 | /** @var int */ |
||
125 | protected $_slow_query_secs = 5; |
||
126 | |||
127 | /** @var array */ |
||
128 | protected $_pagination_attribs = [ |
||
129 | '_limit', |
||
130 | '_offset', |
||
131 | '_order', |
||
132 | '_fields', |
||
133 | '_search' |
||
134 | ]; |
||
135 | |||
136 | /** @var string $_table_name */ |
||
137 | protected $_table_name = null; |
||
138 | |||
139 | /** @var string $_table_alias */ |
||
140 | protected $_table_alias = null; |
||
141 | |||
142 | /** @var string $_display_column */ |
||
143 | protected $_display_column = null; |
||
144 | |||
145 | /** @var string $_connection_name */ |
||
146 | protected $_connection_name = null; |
||
147 | |||
148 | /** @var array $_schema */ |
||
149 | protected $_schema = []; |
||
150 | |||
151 | /** @var array $_virtual_fields */ |
||
152 | protected $_virtual_fields = []; |
||
153 | |||
154 | /** @var array $_errors */ |
||
155 | protected $_errors = []; |
||
156 | |||
157 | /** |
||
158 | * @var int - true = connection default x days |
||
159 | * - false = no cache |
||
160 | * - int = a specific amount |
||
161 | */ |
||
162 | protected $_cache_ttl = self::CACHE_NO; |
||
163 | |||
164 | /** @var string */ |
||
165 | protected $_tmp_table_prefix = 'tmp_'; |
||
166 | |||
167 | /** @var null|string */ |
||
168 | protected $_built_query = null; |
||
169 | |||
170 | // Make handlers public so whe can delete them externally to reduce memory in hhmv |
||
171 | //protected $_handlers = []; |
||
172 | public $_handlers = []; |
||
173 | |||
174 | /** @var bool User want to directly specify the fields */ |
||
175 | protected $_explicit_select_mode = false; |
||
176 | |||
177 | /** @var string[] */ |
||
178 | protected $_update_raw = []; |
||
179 | |||
180 | protected $_max_callback_failures = null; |
||
181 | |||
182 | protected $_num_callback_failures = 0; |
||
183 | |||
184 | protected $_filter_on_fetch = false; |
||
185 | |||
186 | protected $_log_filter_changes = true; |
||
187 | |||
188 | protected $_include_count = false; |
||
189 | |||
190 | /** |
||
191 | * @param AbstractPdo|null $connection |
||
192 | */ |
||
193 | public function __construct(AbstractPdo $connection=null) |
||
200 | |||
201 | public function init() |
||
203 | |||
204 | /** |
||
205 | * @return AbstractPdo |
||
206 | * @throws Exception |
||
207 | */ |
||
208 | public function getPdo() |
||
212 | |||
213 | /** |
||
214 | * @return AbstractLogger |
||
215 | */ |
||
216 | public function getLogger() |
||
220 | |||
221 | /** |
||
222 | * @return RedisCache |
||
223 | */ |
||
224 | public function getCache() |
||
228 | |||
229 | /** |
||
230 | * Define the working table and create a new instance |
||
231 | * |
||
232 | * @param string $tableName - Table name |
||
233 | * @param string $alias - The table alias name |
||
234 | * @param string $displayColumn |
||
235 | * @param string $primaryKeyName |
||
236 | * |
||
237 | * @return $this |
||
238 | */ |
||
239 | public function table($tableName, $alias='', $displayColumn='', $primaryKeyName='id') |
||
247 | |||
248 | /** |
||
249 | * @param $primaryKeyName |
||
250 | * @return $this |
||
251 | */ |
||
252 | public function primaryKeyName($primaryKeyName) |
||
257 | |||
258 | /** |
||
259 | * @param $tableName |
||
260 | * |
||
261 | * @return $this |
||
262 | */ |
||
263 | public function tableName($tableName) |
||
268 | |||
269 | /** |
||
270 | * @param $explicitSelect |
||
271 | * |
||
272 | * @return $this |
||
273 | */ |
||
274 | public function explicitSelectMode($explicitSelect=true) |
||
279 | |||
280 | /** |
||
281 | * @param bool $filterOnFetch |
||
282 | * |
||
283 | * @return $this |
||
284 | */ |
||
285 | public function filterOnFetch($filterOnFetch=true) |
||
290 | |||
291 | /** |
||
292 | * @param bool $logFilterChanges |
||
293 | * |
||
294 | * @return $this |
||
295 | */ |
||
296 | public function logFilterChanges($logFilterChanges=true) |
||
301 | |||
302 | /** |
||
303 | * Return the name of the table |
||
304 | * |
||
305 | * @return string |
||
306 | */ |
||
307 | public function getTableName() |
||
311 | |||
312 | /** |
||
313 | * @return string |
||
314 | */ |
||
315 | public function getDisplayColumn() |
||
319 | |||
320 | /** |
||
321 | * Set the display column |
||
322 | * |
||
323 | * @param string $column |
||
324 | * |
||
325 | * @return $this |
||
326 | */ |
||
327 | public function displayColumn($column) |
||
332 | /** |
||
333 | * Set the table alias |
||
334 | * |
||
335 | * @param string $alias |
||
336 | * |
||
337 | * @return $this |
||
338 | */ |
||
339 | public function tableAlias($alias) |
||
344 | |||
345 | /** |
||
346 | * @param int $cacheTtl |
||
347 | * @return $this |
||
348 | * @throws Exception |
||
349 | */ |
||
350 | protected function _cacheTtl($cacheTtl) |
||
360 | |||
361 | /** |
||
362 | * @return string |
||
363 | */ |
||
364 | public function getTableAlias() |
||
368 | |||
369 | /** |
||
370 | * @param array $associations |
||
371 | * |
||
372 | * @return $this |
||
373 | */ |
||
374 | public function associations(array $associations) |
||
379 | |||
380 | /** |
||
381 | * @param string $alias |
||
382 | * @param array $definition |
||
383 | * @return $this |
||
384 | */ |
||
385 | public function setBelongsTo($alias, array $definition) |
||
393 | |||
394 | public function setBelongsToDisplayField($alias, $displayField) |
||
403 | |||
404 | /** |
||
405 | * @param PDOStatement $stmt |
||
406 | * |
||
407 | * @param PDOStatement $stmt |
||
408 | * @param Closure $fnCallback |
||
409 | * @return bool|stdClass |
||
410 | */ |
||
411 | public function fetchRow(PDOStatement $stmt, Closure $fnCallback=null) |
||
430 | |||
431 | /** |
||
432 | * @param array $schema |
||
433 | * |
||
434 | * @return $this |
||
435 | */ |
||
436 | public function schema(array $schema) |
||
441 | |||
442 | /** |
||
443 | * @param string|array $field |
||
444 | * @param $type |
||
445 | * @return $this |
||
446 | */ |
||
447 | public function addSchema($field, $type) |
||
460 | |||
461 | /** |
||
462 | * @param $keys_only |
||
463 | * @return array |
||
464 | */ |
||
465 | public function getColumns($keys_only=true) |
||
469 | |||
470 | /** |
||
471 | * Get the primary key name |
||
472 | * |
||
473 | * @return string |
||
474 | */ |
||
475 | public function getPrimaryKeyName() |
||
479 | |||
480 | /** |
||
481 | * @param string $query |
||
482 | * @param array $parameters |
||
483 | * |
||
484 | * @return bool |
||
485 | * @throws Exception |
||
486 | */ |
||
487 | public function execute($query, array $parameters=[]) |
||
510 | |||
511 | /** |
||
512 | * @param string $query |
||
513 | * @param array $params |
||
514 | * @return $this |
||
515 | */ |
||
516 | public function query($query, array $params=[]) |
||
522 | |||
523 | /** |
||
524 | * @return bool |
||
525 | */ |
||
526 | public function begin() |
||
530 | |||
531 | /** |
||
532 | * @return bool |
||
533 | */ |
||
534 | public function commit() |
||
538 | |||
539 | /** |
||
540 | * @return bool |
||
541 | */ |
||
542 | public function rollback() |
||
547 | |||
548 | |||
549 | /** |
||
550 | * @param string $sql |
||
551 | * @param array $params |
||
552 | * |
||
553 | * @return string |
||
554 | */ |
||
555 | public function buildQuery($sql, array $params=[]) |
||
581 | |||
582 | /** |
||
583 | * @param stdClass $record |
||
584 | * |
||
585 | * @return stdClass |
||
586 | */ |
||
587 | protected function _trimAndLowerCaseKeys(stdClass $record) |
||
596 | |||
597 | /** |
||
598 | * Return the number of affected row by the last statement |
||
599 | * |
||
600 | * @return int |
||
601 | */ |
||
602 | public function rowCount() |
||
607 | |||
608 | /** |
||
609 | * @return PDOStatement |
||
610 | * @throws PDOException |
||
611 | */ |
||
612 | public function fetchStmt() |
||
620 | |||
621 | /** |
||
622 | * @param bool $build |
||
623 | * @return array |
||
624 | */ |
||
625 | public function fetchSqlQuery($build=false) |
||
634 | |||
635 | /** |
||
636 | * @param string $table_name |
||
637 | * @param bool $drop_if_exists |
||
638 | * @param array $indexes |
||
639 | * @return $this |
||
640 | * @throws Exception |
||
641 | */ |
||
642 | public function fetchIntoMemoryTable($table_name, $drop_if_exists=true, array $indexes=[]) |
||
663 | |||
664 | /** |
||
665 | * @param null $keyedOn |
||
666 | * @param int $cacheTtl |
||
667 | * @return mixed |
||
668 | */ |
||
669 | public function fetch($keyedOn=null, $cacheTtl=self::CACHE_NO) |
||
704 | |||
705 | protected function _parseWhereForPrimaryLookup() |
||
720 | |||
721 | /** |
||
722 | * @param string $cacheKey |
||
723 | * @param Closure $func |
||
724 | * @param int $cacheTtl - 0 for default ttl, -1 for no cache or int for custom ttl |
||
725 | * @return mixed|null |
||
726 | */ |
||
727 | protected function _cacheData($cacheKey, Closure $func, $cacheTtl=self::CACHE_DEFAULT) |
||
764 | |||
765 | /** |
||
766 | * @param string $cacheKey |
||
767 | * @return bool |
||
768 | */ |
||
769 | public function clearCache($cacheKey) |
||
773 | |||
774 | /** |
||
775 | * @param string|null $table |
||
776 | * @return bool |
||
777 | */ |
||
778 | public function clearCacheByTable($table=null) |
||
787 | |||
788 | /** |
||
789 | * @param Closure $fnCallback |
||
790 | * @param null $keyedOn |
||
791 | * @param bool $returnSuccessCnt |
||
792 | * @return stdClass[]|int |
||
793 | */ |
||
794 | public function fetchCallback(Closure $fnCallback, $keyedOn=null, $returnSuccessCnt=true) |
||
817 | |||
818 | /** |
||
819 | * @param $numFailures |
||
820 | * @return $this |
||
821 | */ |
||
822 | public function maxCallbackFailures($numFailures) |
||
828 | |||
829 | /** |
||
830 | * @param PDOStatement $stmt |
||
831 | * @param Closure $fnCallback |
||
832 | * @param int $successCnt |
||
833 | * @return bool|null|stdClass |
||
834 | */ |
||
835 | protected function _tallySuccessCount($stmt, Closure $fnCallback, &$successCnt) |
||
864 | |||
865 | /** |
||
866 | * @param null|string $keyedOn |
||
867 | * @param null|mixed $valueField |
||
868 | * @param int $cacheTtl |
||
869 | * @return mixed |
||
870 | */ |
||
871 | public function fetchList($keyedOn=null, $valueField=null, $cacheTtl=self::CACHE_NO) |
||
908 | |||
909 | /** |
||
910 | * @param string $column |
||
911 | * @param int $cacheTtl |
||
912 | * @param bool|true $unique |
||
913 | * @return array|mixed |
||
914 | */ |
||
915 | public function fetchColumn($column, $cacheTtl=self::CACHE_NO, $unique=true) |
||
924 | |||
925 | /** |
||
926 | * @param null|string $field |
||
927 | * @param null|int $itemId |
||
928 | * @param int $cacheTtl |
||
929 | * @return mixed|null |
||
930 | */ |
||
931 | public function fetchField($field=null, $itemId=null, $cacheTtl=self::CACHE_NO) |
||
954 | |||
955 | /** |
||
956 | * @param int|null $id |
||
957 | * @param int $cacheTtl |
||
958 | * @return \stdClass|bool |
||
959 | */ |
||
960 | public function fetchOne($id=null, $cacheTtl=self::CACHE_NO) |
||
971 | |||
972 | /** |
||
973 | * @param int|null $id |
||
974 | * @param int $cacheTtl |
||
975 | * @return \stdClass|bool |
||
976 | */ |
||
977 | public function fetchExists($id=null, $cacheTtl=self::CACHE_NO) |
||
986 | |||
987 | /*------------------------------------------------------------------------------ |
||
988 | Fluent Query Builder |
||
989 | *-----------------------------------------------------------------------------*/ |
||
990 | |||
991 | /** |
||
992 | * Create the select clause |
||
993 | * |
||
994 | * @param mixed $columns - the column to select. Can be string or array of fields |
||
995 | * @param string $alias - an alias to the column |
||
996 | * @param bool|true $explicitSelect |
||
997 | * @return $this |
||
998 | */ |
||
999 | public function select($columns='*', $alias=null, $explicitSelect=true) |
||
1039 | |||
1040 | public function selectRaw($select) |
||
1045 | |||
1046 | /** |
||
1047 | * @param bool $log_queries |
||
1048 | * |
||
1049 | * @return $this |
||
1050 | */ |
||
1051 | public function logQueries($log_queries=true) |
||
1056 | |||
1057 | /** |
||
1058 | * @param bool $include_count |
||
1059 | * |
||
1060 | * @return $this |
||
1061 | */ |
||
1062 | public function includeCount($include_count=true) |
||
1067 | |||
1068 | /** |
||
1069 | * @param bool $distinct |
||
1070 | * |
||
1071 | * @return $this |
||
1072 | */ |
||
1073 | public function distinct($distinct=true) |
||
1078 | |||
1079 | /** |
||
1080 | * @param array $fields |
||
1081 | * @return $this |
||
1082 | */ |
||
1083 | public function withBelongsTo($fields=[]) |
||
1095 | |||
1096 | /** |
||
1097 | * @param string $alias |
||
1098 | * @param string $type |
||
1099 | * @param bool $addSelectField |
||
1100 | * @return $this |
||
1101 | */ |
||
1102 | public function autoJoin($alias, $type=self::LEFT_JOIN, $addSelectField=true) |
||
1118 | |||
1119 | /** |
||
1120 | * Add where condition, more calls appends with AND |
||
1121 | * |
||
1122 | * @param string $condition possibly containing ? or :name |
||
1123 | * @param mixed $parameters accepted by PDOStatement::execute or a scalar value |
||
1124 | * @param mixed ... |
||
1125 | * @return $this |
||
1126 | */ |
||
1127 | public function where($condition, $parameters = []) |
||
1174 | |||
1175 | /** |
||
1176 | * Create an AND operator in the where clause |
||
1177 | * |
||
1178 | * @return $this |
||
1179 | */ |
||
1180 | public function _and() |
||
1192 | |||
1193 | |||
1194 | /** |
||
1195 | * Create an OR operator in the where clause |
||
1196 | * |
||
1197 | * @return $this |
||
1198 | */ |
||
1199 | public function _or() |
||
1211 | |||
1212 | /** |
||
1213 | * To group multiple where clauses together. |
||
1214 | * |
||
1215 | * @return $this |
||
1216 | */ |
||
1217 | public function wrap() |
||
1226 | |||
1227 | /** |
||
1228 | * Where Primary key |
||
1229 | * |
||
1230 | * @param integer $id |
||
1231 | * @param bool $addAlias |
||
1232 | * |
||
1233 | * @return $this |
||
1234 | */ |
||
1235 | public function wherePK($id, $addAlias=true) |
||
1240 | |||
1241 | /** |
||
1242 | * WHERE $columnName != $value |
||
1243 | * |
||
1244 | * @param string $columnName |
||
1245 | * @param mixed $value |
||
1246 | * @return $this |
||
1247 | */ |
||
1248 | public function whereNot($columnName, $value) |
||
1252 | /** |
||
1253 | * WHERE $columnName != $value |
||
1254 | * |
||
1255 | * @param string $columnName |
||
1256 | * @param mixed $value |
||
1257 | * @return $this |
||
1258 | */ |
||
1259 | public function whereCoercedNot($columnName, $value) |
||
1263 | |||
1264 | /** |
||
1265 | * WHERE $columnName LIKE $value |
||
1266 | * |
||
1267 | * @param string $columnName |
||
1268 | * @param mixed $value |
||
1269 | * @return $this |
||
1270 | */ |
||
1271 | public function whereLike($columnName, $value) |
||
1275 | |||
1276 | /** |
||
1277 | * @param string $columnName |
||
1278 | * @param mixed $value1 |
||
1279 | * @param mixed $value2 |
||
1280 | * @return $this |
||
1281 | */ |
||
1282 | public function whereBetween($columnName, $value1, $value2) |
||
1286 | |||
1287 | /** |
||
1288 | * @param string $columnName |
||
1289 | * @param mixed $value1 |
||
1290 | * @param mixed $value2 |
||
1291 | * @return $this |
||
1292 | */ |
||
1293 | public function whereNotBetween($columnName, $value1, $value2) |
||
1297 | |||
1298 | /** |
||
1299 | * @param string $columnName |
||
1300 | * @param string $regex |
||
1301 | * @return $this |
||
1302 | */ |
||
1303 | public function whereRegex($columnName, $regex) |
||
1307 | |||
1308 | /** |
||
1309 | * @param string $columnName |
||
1310 | * @param string $regex |
||
1311 | * @return $this |
||
1312 | */ |
||
1313 | public function whereNotRegex($columnName, $regex) |
||
1317 | |||
1318 | /** |
||
1319 | * WHERE $columnName NOT LIKE $value |
||
1320 | * |
||
1321 | * @param string $columnName |
||
1322 | * @param mixed $value |
||
1323 | * @return $this |
||
1324 | */ |
||
1325 | public function whereNotLike($columnName, $value) |
||
1329 | |||
1330 | /** |
||
1331 | * WHERE $columnName > $value |
||
1332 | * |
||
1333 | * @param string $columnName |
||
1334 | * @param mixed $value |
||
1335 | * @return $this |
||
1336 | */ |
||
1337 | public function whereGt($columnName, $value) |
||
1341 | |||
1342 | /** |
||
1343 | * WHERE $columnName >= $value |
||
1344 | * |
||
1345 | * @param string $columnName |
||
1346 | * @param mixed $value |
||
1347 | * @return $this |
||
1348 | */ |
||
1349 | public function whereGte($columnName, $value) |
||
1353 | |||
1354 | /** |
||
1355 | * WHERE $columnName < $value |
||
1356 | * |
||
1357 | * @param string $columnName |
||
1358 | * @param mixed $value |
||
1359 | * @return $this |
||
1360 | */ |
||
1361 | public function whereLt($columnName, $value) |
||
1365 | |||
1366 | /** |
||
1367 | * WHERE $columnName <= $value |
||
1368 | * |
||
1369 | * @param string $columnName |
||
1370 | * @param mixed $value |
||
1371 | * @return $this |
||
1372 | */ |
||
1373 | public function whereLte($columnName, $value) |
||
1377 | |||
1378 | /** |
||
1379 | * WHERE $columnName IN (?,?,?,...) |
||
1380 | * |
||
1381 | * @param string $columnName |
||
1382 | * @param array $values |
||
1383 | * @return $this |
||
1384 | */ |
||
1385 | public function whereIn($columnName, array $values) |
||
1389 | |||
1390 | /** |
||
1391 | * WHERE $columnName NOT IN (?,?,?,...) |
||
1392 | * |
||
1393 | * @param string $columnName |
||
1394 | * @param array $values |
||
1395 | * @return $this |
||
1396 | */ |
||
1397 | public function whereNotIn($columnName, array $values) |
||
1402 | |||
1403 | /** |
||
1404 | * WHERE $columnName IS NULL |
||
1405 | * |
||
1406 | * @param string $columnName |
||
1407 | * @return $this |
||
1408 | */ |
||
1409 | public function whereNull($columnName) |
||
1413 | |||
1414 | /** |
||
1415 | * WHERE $columnName IS NOT NULL |
||
1416 | * |
||
1417 | * @param string $columnName |
||
1418 | * @return $this |
||
1419 | */ |
||
1420 | public function whereNotNull($columnName) |
||
1424 | |||
1425 | /** |
||
1426 | * @param string $statement |
||
1427 | * @param string $operator |
||
1428 | * @return $this |
||
1429 | */ |
||
1430 | public function having($statement, $operator = self::OPERATOR_AND) |
||
1438 | |||
1439 | /** |
||
1440 | * ORDER BY $columnName (ASC | DESC) |
||
1441 | * |
||
1442 | * @param string $columnName - The name of the column or an expression |
||
1443 | * @param string $ordering (DESC | ASC) |
||
1444 | * @return $this |
||
1445 | */ |
||
1446 | public function orderBy($columnName, $ordering=null) |
||
1457 | |||
1458 | /** |
||
1459 | * GROUP BY $columnName |
||
1460 | * |
||
1461 | * @param string $columnName |
||
1462 | * @return $this |
||
1463 | */ |
||
1464 | public function groupBy($columnName) |
||
1473 | |||
1474 | |||
1475 | /** |
||
1476 | * LIMIT $limit |
||
1477 | * |
||
1478 | * @param int $limit |
||
1479 | * @param int|null $offset |
||
1480 | * @return $this |
||
1481 | */ |
||
1482 | public function limit($limit, $offset=null) |
||
1491 | |||
1492 | /** |
||
1493 | * Return the limit |
||
1494 | * |
||
1495 | * @return integer |
||
1496 | */ |
||
1497 | public function getLimit() |
||
1501 | |||
1502 | /** |
||
1503 | * OFFSET $offset |
||
1504 | * |
||
1505 | * @param int $offset |
||
1506 | * @return $this |
||
1507 | */ |
||
1508 | public function offset($offset) |
||
1513 | |||
1514 | /** |
||
1515 | * Return the offset |
||
1516 | * |
||
1517 | * @return integer |
||
1518 | */ |
||
1519 | public function getOffset() |
||
1523 | |||
1524 | /** |
||
1525 | * Build a join |
||
1526 | * |
||
1527 | * @param string $table - The table name |
||
1528 | * @param string $constraint -> id = profile.user_id |
||
1529 | * @param string $tableAlias - The alias of the table name |
||
1530 | * @param string $joinOperator - LEFT | INNER | etc... |
||
1531 | * @return $this |
||
1532 | */ |
||
1533 | public function join($table, $constraint=null, $tableAlias = null, $joinOperator = '') |
||
1551 | |||
1552 | /** |
||
1553 | * Create a left join |
||
1554 | * |
||
1555 | * @param string $table |
||
1556 | * @param string $constraint |
||
1557 | * @param string $tableAlias |
||
1558 | * @return $this |
||
1559 | */ |
||
1560 | public function leftJoin($table, $constraint, $tableAlias=null) |
||
1564 | |||
1565 | |||
1566 | /** |
||
1567 | * Return the build select query |
||
1568 | * |
||
1569 | * @return string |
||
1570 | */ |
||
1571 | public function getSelectQuery() |
||
1613 | |||
1614 | /** |
||
1615 | * Prepare columns to include the table alias name |
||
1616 | * @param array $columns |
||
1617 | * @return array |
||
1618 | */ |
||
1619 | protected function _prepareColumns(array $columns) |
||
1648 | |||
1649 | /** |
||
1650 | * Build the WHERE clause(s) |
||
1651 | * |
||
1652 | * @param bool $purgeAliases |
||
1653 | * @return string |
||
1654 | */ |
||
1655 | protected function _getWhereString($purgeAliases=false) |
||
1687 | |||
1688 | /** |
||
1689 | * Return the HAVING clause |
||
1690 | * |
||
1691 | * @return string |
||
1692 | */ |
||
1693 | protected function _getHavingString() |
||
1711 | |||
1712 | /** |
||
1713 | * Return the values to be bound for where |
||
1714 | * |
||
1715 | * @param bool $purgeAliases |
||
1716 | * @return array |
||
1717 | */ |
||
1718 | protected function _getWhereParameters($purgeAliases=false) |
||
1723 | |||
1724 | /** |
||
1725 | * Insert new rows |
||
1726 | * $records can be a stdClass or an array of stdClass to add a bulk insert |
||
1727 | * If a single row is inserted, it will return it's row instance |
||
1728 | * |
||
1729 | * @param stdClass|array $records |
||
1730 | * @return int|stdClass|bool |
||
1731 | * @throws Exception |
||
1732 | */ |
||
1733 | public function insert($records) |
||
1763 | |||
1764 | /** |
||
1765 | * @param null $name |
||
1766 | * @return int |
||
1767 | */ |
||
1768 | public function getLastInsertId($name=null) |
||
1772 | |||
1773 | /** |
||
1774 | * @param $records |
||
1775 | * @return array |
||
1776 | */ |
||
1777 | public function insertSqlQuery($records) |
||
1797 | |||
1798 | /** |
||
1799 | * @param $data |
||
1800 | * @param array $matchOn |
||
1801 | * @param bool $returnObj |
||
1802 | * @return bool|int|stdClass |
||
1803 | */ |
||
1804 | public function upsert($data, array $matchOn=[], $returnObj=false) |
||
1825 | |||
1826 | /** |
||
1827 | * @param stdClass $object |
||
1828 | * @param array $matchOn |
||
1829 | * @param bool $returnObj |
||
1830 | * @return bool|int|stdClass |
||
1831 | */ |
||
1832 | public function upsertOne(stdClass $object, array $matchOn=[], $returnObj=false) |
||
1870 | |||
1871 | /** |
||
1872 | * @param array $data |
||
1873 | * @param array $matchOn |
||
1874 | * @param bool|false $returnObj |
||
1875 | * @return bool|int|stdClass |
||
1876 | */ |
||
1877 | public function upsertArr(array $data, array $matchOn=[], $returnObj=false) |
||
1881 | |||
1882 | /** |
||
1883 | * Update entries |
||
1884 | * Use the query builder to create the where clause |
||
1885 | * |
||
1886 | * @param stdClass $record |
||
1887 | * @param bool $updateAll |
||
1888 | * @return bool|int |
||
1889 | * @throws Exception |
||
1890 | */ |
||
1891 | public function update(stdClass $record, $updateAll=false) |
||
1913 | |||
1914 | /** |
||
1915 | * @param array $record |
||
1916 | * @param bool|false $updateAll |
||
1917 | * @return bool|int |
||
1918 | * @throws Exception |
||
1919 | */ |
||
1920 | public function updateArr(array $record, $updateAll=false) |
||
1924 | |||
1925 | /** |
||
1926 | * @param array $record |
||
1927 | * @return bool|int|stdClass |
||
1928 | */ |
||
1929 | public function insertArr(array $record) |
||
1933 | |||
1934 | /** |
||
1935 | * @param int $field |
||
1936 | * @param mixed $value |
||
1937 | * @param null $id |
||
1938 | * @param bool|false $updateAll |
||
1939 | * @return bool|int |
||
1940 | * @throws Exception |
||
1941 | */ |
||
1942 | public function updateField($field, $value, $id=null, $updateAll=false) |
||
1950 | |||
1951 | /** |
||
1952 | * @param int $field |
||
1953 | * @param mixed $value |
||
1954 | * @param null $id |
||
1955 | * @param bool|false $updateAll |
||
1956 | * @return bool|int |
||
1957 | * @throws Exception |
||
1958 | */ |
||
1959 | public function concatField($field, $value, $id=null, $updateAll=false) |
||
1963 | |||
1964 | /** |
||
1965 | * @param stdClass $record |
||
1966 | * @return bool|int |
||
1967 | * @throws Exception |
||
1968 | */ |
||
1969 | public function updateChanged(stdClass $record) |
||
1982 | |||
1983 | /** |
||
1984 | * @param string $expression |
||
1985 | * @param array $params |
||
1986 | * @return $this |
||
1987 | */ |
||
1988 | public function updateByExpression($expression, array $params) |
||
1993 | |||
1994 | /** |
||
1995 | * @param array $data |
||
1996 | * @return int |
||
1997 | * @throws Exception |
||
1998 | */ |
||
1999 | public function rawUpdate(array $data=[]) |
||
2007 | |||
2008 | /** |
||
2009 | * @param stdClass $record |
||
2010 | * @return array |
||
2011 | */ |
||
2012 | public function updateSqlQuery(stdClass $record) |
||
2022 | |||
2023 | /** |
||
2024 | * @param $record |
||
2025 | * @return array |
||
2026 | */ |
||
2027 | protected function updateSql(array $record) |
||
2057 | |||
2058 | /** |
||
2059 | * Delete rows |
||
2060 | * Use the query builder to create the where clause |
||
2061 | * @param bool $deleteAll = When there is no where condition, setting to true will delete all |
||
2062 | * @return int - total affected rows |
||
2063 | * @throws Exception |
||
2064 | */ |
||
2065 | public function delete($deleteAll=false) |
||
2075 | |||
2076 | /** |
||
2077 | * @param bool|false $force |
||
2078 | * @return $this |
||
2079 | * @throws Exception |
||
2080 | */ |
||
2081 | public function truncate($force=false) |
||
2094 | |||
2095 | /** |
||
2096 | * @return array |
||
2097 | */ |
||
2098 | public function deleteSqlQuery() |
||
2108 | |||
2109 | |||
2110 | /** |
||
2111 | * Return the aggregate count of column |
||
2112 | * |
||
2113 | * @param string $column |
||
2114 | * @param int $cacheTtl |
||
2115 | * @return int |
||
2116 | */ |
||
2117 | public function count($column='*', $cacheTtl=self::CACHE_NO) |
||
2124 | |||
2125 | |||
2126 | /** |
||
2127 | * Return the aggregate max count of column |
||
2128 | * |
||
2129 | * @param string $column |
||
2130 | * @param int $cacheTtl |
||
2131 | * @return mixed|null |
||
2132 | */ |
||
2133 | public function max($column, $cacheTtl=self::CACHE_NO) |
||
2140 | |||
2141 | |||
2142 | /** |
||
2143 | * Return the aggregate min count of column |
||
2144 | * |
||
2145 | * @param string $column |
||
2146 | * @param int $cacheTtl |
||
2147 | * @return mixed|null |
||
2148 | */ |
||
2149 | public function min($column, $cacheTtl=self::CACHE_NO) |
||
2156 | |||
2157 | /** |
||
2158 | * Return the aggregate sum count of column |
||
2159 | * |
||
2160 | * @param string $column |
||
2161 | * @param int $cacheTtl |
||
2162 | * @return mixed|null |
||
2163 | */ |
||
2164 | public function sum($column, $cacheTtl=self::CACHE_NO) |
||
2171 | |||
2172 | /** |
||
2173 | * Return the aggregate average count of column |
||
2174 | * |
||
2175 | * @param string $column |
||
2176 | * @param int $cacheTtl |
||
2177 | * @return mixed|null |
||
2178 | */ |
||
2179 | public function avg($column, $cacheTtl=self::CACHE_NO) |
||
2186 | |||
2187 | /*******************************************************************************/ |
||
2188 | // Utilities methods |
||
2189 | |||
2190 | /** |
||
2191 | * Reset fields |
||
2192 | * |
||
2193 | * @return $this |
||
2194 | */ |
||
2195 | public function reset() |
||
2222 | |||
2223 | /** |
||
2224 | * Return a YYYY-MM-DD HH:II:SS date format |
||
2225 | * |
||
2226 | * @param string $datetime - An english textual datetime description |
||
2227 | * now, yesterday, 3 days ago, +1 week |
||
2228 | * http://php.net/manual/en/function.strtotime.php |
||
2229 | * @return string YYYY-MM-DD HH:II:SS |
||
2230 | */ |
||
2231 | public static function NOW($datetime = 'now') |
||
2235 | |||
2236 | /** |
||
2237 | * Return a string containing the given number of question marks, |
||
2238 | * separated by commas. Eg '?, ?, ?' |
||
2239 | * |
||
2240 | * @param int - total of placeholder to insert |
||
2241 | * @return string |
||
2242 | */ |
||
2243 | protected function _makePlaceholders($number_of_placeholders=1) |
||
2247 | |||
2248 | /** |
||
2249 | * Format the table{Primary|Foreign}KeyName |
||
2250 | * |
||
2251 | * @param string $pattern |
||
2252 | * @param string $tableName |
||
2253 | * @return string |
||
2254 | */ |
||
2255 | protected function _formatKeyName($pattern, $tableName) |
||
2259 | |||
2260 | /** |
||
2261 | * @param string $query |
||
2262 | * @param array $parameters |
||
2263 | * |
||
2264 | * @return array |
||
2265 | */ |
||
2266 | protected function _logQuery($query, array $parameters) |
||
2278 | |||
2279 | /** |
||
2280 | * @param $ident |
||
2281 | * @param $builtQuery |
||
2282 | */ |
||
2283 | protected function _logSlowQueries($ident, $builtQuery) |
||
2296 | |||
2297 | /** |
||
2298 | * @return float |
||
2299 | */ |
||
2300 | public function getTimeTaken() |
||
2305 | |||
2306 | /** |
||
2307 | * @param $secs |
||
2308 | * @return $this |
||
2309 | */ |
||
2310 | public function slowQuerySeconds($secs) |
||
2316 | |||
2317 | |||
2318 | /** |
||
2319 | * @param $field |
||
2320 | * @param array $values |
||
2321 | * @param null $placeholder_prefix |
||
2322 | * |
||
2323 | * @return array |
||
2324 | */ |
||
2325 | public function getNamedWhereIn($field, array $values, $placeholder_prefix=null) |
||
2346 | |||
2347 | /** |
||
2348 | * @param $field |
||
2349 | * @param string $delimiter |
||
2350 | * |
||
2351 | * @return array |
||
2352 | */ |
||
2353 | protected function _getColumnAliasParts($field, $delimiter=':') |
||
2362 | |||
2363 | /** |
||
2364 | * @param string $column |
||
2365 | * @param string $term |
||
2366 | * @return $this |
||
2367 | */ |
||
2368 | protected function _addWhereClause($column, $term) |
||
2424 | |||
2425 | public function destroy() |
||
2434 | |||
2435 | public function __destruct() |
||
2439 | |||
2440 | /** @var string */ |
||
2441 | static protected $_model_namespace = ''; |
||
2442 | |||
2443 | /** @var bool */ |
||
2444 | protected $_validation_exceptions = true; |
||
2445 | |||
2446 | /** @var array */ |
||
2447 | protected $_paging_meta = []; |
||
2448 | |||
2449 | /** @var int */ |
||
2450 | protected $_default_max = 100; |
||
2451 | |||
2452 | /** |
||
2453 | * Load a model |
||
2454 | * |
||
2455 | * @param string $model_name |
||
2456 | * @param AbstractPdo $connection |
||
2457 | * @return Model |
||
2458 | * @throws ModelNotFoundException |
||
2459 | */ |
||
2460 | public static function loadModel($model_name, AbstractPdo $connection=null) |
||
2469 | |||
2470 | /** |
||
2471 | * Load a model |
||
2472 | * |
||
2473 | * @param string $table_name |
||
2474 | * @param AbstractPdo $connection |
||
2475 | * @return $this |
||
2476 | */ |
||
2477 | public static function loadTable($table_name, AbstractPdo $connection=null) |
||
2483 | |||
2484 | /** |
||
2485 | * @param string $columnName |
||
2486 | * @param int $cacheTtl |
||
2487 | * @param bool $flushCache |
||
2488 | * @return bool |
||
2489 | */ |
||
2490 | public function columnExists($columnName, $cacheTtl=self::CACHE_NO, $flushCache=false) |
||
2495 | |||
2496 | /** |
||
2497 | * @param int $cacheTtl |
||
2498 | * @param bool $flushCache |
||
2499 | * @return $this |
||
2500 | */ |
||
2501 | public function loadSchemaFromDb($cacheTtl=self::CACHE_NO, $flushCache=false) |
||
2507 | |||
2508 | /** |
||
2509 | * @param int $cacheTtl |
||
2510 | * @param bool $flushCache |
||
2511 | * @return array |
||
2512 | * @throws \Terah\Assert\AssertionFailedException |
||
2513 | */ |
||
2514 | public function getSchemaFromDb($cacheTtl=self::CACHE_NO, $flushCache=false) |
||
2526 | |||
2527 | /** |
||
2528 | * @param string $table |
||
2529 | * @param int $cacheTtl |
||
2530 | * @param bool $flushCache |
||
2531 | * @return array |
||
2532 | */ |
||
2533 | protected function _getColumnsByTableFromDb($table, $cacheTtl=self::CACHE_NO, $flushCache=false) |
||
2548 | |||
2549 | /** |
||
2550 | * @param string $table |
||
2551 | * @return bool |
||
2552 | */ |
||
2553 | public function clearSchemaCache($table) |
||
2557 | |||
2558 | /** |
||
2559 | * @param stdClass $record |
||
2560 | * @return stdClass |
||
2561 | */ |
||
2562 | public function onFetch(stdClass $record) |
||
2571 | |||
2572 | /** |
||
2573 | * @param stdClass $record |
||
2574 | * @return stdClass |
||
2575 | */ |
||
2576 | public function cleanseRecord(stdClass $record) |
||
2592 | |||
2593 | /** |
||
2594 | * @param stdClass $record |
||
2595 | * @param string $type |
||
2596 | * @return stdClass |
||
2597 | */ |
||
2598 | public function beforeSave(stdClass $record, $type) |
||
2606 | |||
2607 | /** |
||
2608 | * @param stdClass $record |
||
2609 | * @param string $type |
||
2610 | * @return stdClass |
||
2611 | */ |
||
2612 | public function afterSave(stdClass $record, $type) |
||
2618 | |||
2619 | /** |
||
2620 | * @param stdClass $record |
||
2621 | * @param string $type |
||
2622 | * @return stdClass |
||
2623 | */ |
||
2624 | public function addDefaultFields(stdClass $record, $type) |
||
2629 | |||
2630 | public function applyGlobalModifiers(stdClass $record, $type) |
||
2635 | |||
2636 | public function removeUnneededFields(\stdClass $record, $type) |
||
2654 | |||
2655 | /** |
||
2656 | * @param array $data |
||
2657 | * @param string $saveType |
||
2658 | * @return array |
||
2659 | */ |
||
2660 | public function cleanseWebData($data, $saveType) |
||
2674 | |||
2675 | /** |
||
2676 | * @return array |
||
2677 | */ |
||
2678 | public function skeleton() |
||
2688 | |||
2689 | |||
2690 | /** |
||
2691 | * @return Closure[] |
||
2692 | */ |
||
2693 | protected function _getFieldHandlers() |
||
2697 | |||
2698 | /** |
||
2699 | * @param bool $toString |
||
2700 | * @return array|string |
||
2701 | */ |
||
2702 | public function getErrors($toString=false) |
||
2715 | |||
2716 | /** |
||
2717 | * @param bool $throw |
||
2718 | * @return $this |
||
2719 | */ |
||
2720 | public function validationExceptions($throw=true) |
||
2725 | |||
2726 | /** |
||
2727 | * @param array $query array('_limit' => int, '_offset' => int, '_order' => string, '_fields' => string, _search) |
||
2728 | * |
||
2729 | * @return $this |
||
2730 | * @throws Exception |
||
2731 | */ |
||
2732 | public function paginate(array $query=[]) |
||
2741 | |||
2742 | /** |
||
2743 | * @param null|string $limit |
||
2744 | * @param null|string|int $offset |
||
2745 | * @return $this |
||
2746 | */ |
||
2747 | protected function _setLimit($limit=null, $offset=null) |
||
2761 | |||
2762 | /** |
||
2763 | * @param null|string|array $fields |
||
2764 | * @return $this |
||
2765 | * @throws Exception |
||
2766 | */ |
||
2767 | protected function _setFields($fields=null) |
||
2814 | |||
2815 | /** |
||
2816 | * @param null|string $orderBy |
||
2817 | * @return $this|FluentPdoModel |
||
2818 | */ |
||
2819 | protected function _setOrderBy($orderBy=null) |
||
2854 | |||
2855 | /** |
||
2856 | * @param null $type |
||
2857 | * @return array |
||
2858 | */ |
||
2859 | public function getPagingMeta($type=null) |
||
2867 | |||
2868 | /** |
||
2869 | * @return $this |
||
2870 | */ |
||
2871 | public function setPagingMeta() |
||
2892 | |||
2893 | /** |
||
2894 | * Take a web request and format a query |
||
2895 | * |
||
2896 | * @param array $query |
||
2897 | * |
||
2898 | * @return $this |
||
2899 | * @throws Exception |
||
2900 | */ |
||
2901 | public function filter(array $query=[]) |
||
2966 | |||
2967 | /** |
||
2968 | * @param string $column |
||
2969 | * @param $displayCol |
||
2970 | * @return string|null |
||
2971 | */ |
||
2972 | protected function _findFieldByQuery($column, $displayCol) |
||
3017 | |||
3018 | public function getSearchableAssociations() |
||
3023 | |||
3024 | /** |
||
3025 | * @param $keys_only |
||
3026 | * @return array |
||
3027 | */ |
||
3028 | |||
3029 | public function columns($keys_only=true) |
||
3033 | |||
3034 | /** |
||
3035 | * @param string $field |
||
3036 | * @param mixed $value |
||
3037 | * @param bool|false $permissive |
||
3038 | * @return float|int|null|string |
||
3039 | */ |
||
3040 | protected function _fixType($field, $value, $permissive=false) |
||
3079 | |||
3080 | /** |
||
3081 | * @param stdClass $record |
||
3082 | * @param string $type |
||
3083 | * @return stdClass |
||
3084 | */ |
||
3085 | public function fixTypes(stdClass $record, $type=null) |
||
3098 | |||
3099 | /** |
||
3100 | * @param stdClass $record |
||
3101 | * @param string $type |
||
3102 | * @return stdClass |
||
3103 | * @throws Exception |
||
3104 | */ |
||
3105 | public function applyHandlers(stdClass $record, $type='INSERT') |
||
3132 | |||
3133 | /** |
||
3134 | * @param string $field |
||
3135 | * @param mixed $value |
||
3136 | * @param null $type |
||
3137 | * @param null $record |
||
3138 | * @return null |
||
3139 | * @throws Exception |
||
3140 | */ |
||
3141 | protected function applyHandler($field, $value, $type=null, $record=null) |
||
3163 | |||
3164 | protected function _compileHandlers() |
||
3172 | } |
||
3173 | |||
3201 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()
can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.