Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like QueryBuilder 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 QueryBuilder, and based on these observations, apply Extract Interface, too.
1 | <?php declare(strict_types=1); |
||
29 | class QueryBuilder implements QueryBuilderInterface { |
||
30 | |||
31 | // -------------------------------------------------------------------------- |
||
32 | // ! Constants |
||
33 | // -------------------------------------------------------------------------- |
||
34 | |||
35 | const KEY = 0; |
||
36 | const VALUE = 1; |
||
37 | const BOTH = 2; |
||
38 | |||
39 | // -------------------------------------------------------------------------- |
||
40 | // ! SQL Clause Strings |
||
41 | // -------------------------------------------------------------------------- |
||
42 | |||
43 | /** |
||
44 | * Compiled 'select' clause |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $selectString = ''; |
||
48 | |||
49 | /** |
||
50 | * Compiled 'from' clause |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $fromString = ''; |
||
54 | |||
55 | /** |
||
56 | * Compiled arguments for insert / update |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $setString; |
||
60 | |||
61 | /** |
||
62 | * Order by clause |
||
63 | * @var string |
||
64 | */ |
||
65 | protected $orderString; |
||
66 | |||
67 | /** |
||
68 | * Group by clause |
||
69 | * @var string |
||
70 | */ |
||
71 | protected $groupString; |
||
72 | |||
73 | // -------------------------------------------------------------------------- |
||
74 | // ! SQL Clause Arrays |
||
75 | // -------------------------------------------------------------------------- |
||
76 | |||
77 | /** |
||
78 | * Keys for insert/update statement |
||
79 | * @var array |
||
80 | */ |
||
81 | protected $setArrayKeys = []; |
||
82 | |||
83 | /** |
||
84 | * Key/val pairs for order by clause |
||
85 | * @var array |
||
86 | */ |
||
87 | protected $orderArray = []; |
||
88 | |||
89 | /** |
||
90 | * Key/val pairs for group by clause |
||
91 | * @var array |
||
92 | */ |
||
93 | protected $groupArray = []; |
||
94 | |||
95 | // -------------------------------------------------------------------------- |
||
96 | // ! Other Class vars |
||
97 | // -------------------------------------------------------------------------- |
||
98 | |||
99 | /** |
||
100 | * Values to apply to prepared statements |
||
101 | * @var array |
||
102 | */ |
||
103 | protected $values = []; |
||
104 | |||
105 | /** |
||
106 | * Values to apply to where clauses in prepared statements |
||
107 | * @var array |
||
108 | */ |
||
109 | protected $whereValues = []; |
||
110 | |||
111 | /** |
||
112 | * Value for limit string |
||
113 | * @var string |
||
114 | */ |
||
115 | protected $limit; |
||
116 | |||
117 | /** |
||
118 | * Value for offset in limit string |
||
119 | * @var integer |
||
120 | */ |
||
121 | protected $offset; |
||
122 | |||
123 | /** |
||
124 | * Query component order mapping |
||
125 | * for complex select queries |
||
126 | * |
||
127 | * Format: |
||
128 | * array( |
||
129 | * 'type' => 'where', |
||
130 | * 'conjunction' => ' AND ', |
||
131 | * 'string' => 'k=?' |
||
132 | * ) |
||
133 | * |
||
134 | * @var array |
||
135 | */ |
||
136 | protected $queryMap = []; |
||
137 | |||
138 | /** |
||
139 | * Map for having clause |
||
140 | * @var array |
||
141 | */ |
||
142 | protected $havingMap; |
||
143 | |||
144 | /** |
||
145 | * Convenience property for connection management |
||
146 | * @var string |
||
147 | */ |
||
148 | public $connName = ''; |
||
149 | |||
150 | /** |
||
151 | * List of queries executed |
||
152 | * @var array |
||
153 | */ |
||
154 | public $queries; |
||
155 | |||
156 | /** |
||
157 | * Whether to do only an explain on the query |
||
158 | * @var boolean |
||
159 | */ |
||
160 | protected $explain; |
||
161 | |||
162 | /** |
||
163 | * The current database driver |
||
164 | * @var DriverInterface |
||
165 | */ |
||
166 | public $driver; |
||
167 | |||
168 | /** |
||
169 | * Query parser class instance |
||
170 | * @var QueryParser |
||
171 | */ |
||
172 | protected $parser; |
||
173 | |||
174 | /** |
||
175 | * Alias to driver util class |
||
176 | * @var AbstractUtil |
||
177 | */ |
||
178 | protected $util; |
||
179 | |||
180 | /** |
||
181 | * Alias to driver sql class |
||
182 | * @var SQLInterface |
||
183 | */ |
||
184 | protected $sql; |
||
185 | |||
186 | /** |
||
187 | * String class values to be reset |
||
188 | * |
||
189 | * @var array |
||
190 | */ |
||
191 | private $stringVars = [ |
||
192 | 'selectString', |
||
193 | 'fromString', |
||
194 | 'setString', |
||
195 | 'orderString', |
||
196 | 'groupString', |
||
197 | 'limit', |
||
198 | 'offset', |
||
199 | 'explain', |
||
200 | ]; |
||
201 | |||
202 | /** |
||
203 | * Array class variables to be reset |
||
204 | * |
||
205 | * @var array |
||
206 | */ |
||
207 | private $arrayVars = [ |
||
208 | 'setArrayKeys', |
||
209 | 'orderArray', |
||
210 | 'groupArray', |
||
211 | 'values', |
||
212 | 'whereValues', |
||
213 | 'queryMap', |
||
214 | 'havingMap' |
||
215 | ]; |
||
216 | |||
217 | // -------------------------------------------------------------------------- |
||
218 | // ! Methods |
||
219 | // -------------------------------------------------------------------------- |
||
220 | |||
221 | /** |
||
222 | * Constructor |
||
223 | * |
||
224 | * @param DriverInterface $driver |
||
225 | * @param QueryParser $parser |
||
226 | */ |
||
227 | public function __construct(DriverInterface $driver, QueryParser $parser) |
||
239 | |||
240 | /** |
||
241 | * Destructor |
||
242 | * @codeCoverageIgnore |
||
243 | */ |
||
244 | public function __destruct() |
||
248 | |||
249 | /** |
||
250 | * Calls a function further down the inheritance chain |
||
251 | * |
||
252 | * @param string $name |
||
253 | * @param array $params |
||
254 | * @return mixed |
||
255 | * @throws BadMethodCallException |
||
256 | */ |
||
257 | public function __call(string $name, array $params) |
||
276 | |||
277 | // -------------------------------------------------------------------------- |
||
278 | // ! Driver setters |
||
279 | // -------------------------------------------------------------------------- |
||
280 | |||
281 | public function setDriver(DriverInterface $driver) |
||
285 | |||
286 | // -------------------------------------------------------------------------- |
||
287 | // ! Select Queries |
||
288 | // -------------------------------------------------------------------------- |
||
289 | |||
290 | /** |
||
291 | * Specifies rows to select in a query |
||
292 | * |
||
293 | * @param string $fields |
||
294 | * @return QueryBuilderInterface |
||
295 | */ |
||
296 | public function select(string $fields): QueryBuilderInterface |
||
332 | |||
333 | /** |
||
334 | * Selects the maximum value of a field from a query |
||
335 | * |
||
336 | * @param string $field |
||
337 | * @param string|bool $as |
||
338 | * @return QueryBuilderInterface |
||
339 | */ |
||
340 | public function selectMax(string $field, $as=FALSE): QueryBuilderInterface |
||
346 | |||
347 | /** |
||
348 | * Selects the minimum value of a field from a query |
||
349 | * |
||
350 | * @param string $field |
||
351 | * @param string|bool $as |
||
352 | * @return QueryBuilderInterface |
||
353 | */ |
||
354 | public function selectMin(string $field, $as=FALSE): QueryBuilderInterface |
||
360 | |||
361 | /** |
||
362 | * Selects the average value of a field from a query |
||
363 | * |
||
364 | * @param string $field |
||
365 | * @param string|bool $as |
||
366 | * @return QueryBuilderInterface |
||
367 | */ |
||
368 | public function selectAvg(string $field, $as=FALSE): QueryBuilderInterface |
||
374 | |||
375 | /** |
||
376 | * Selects the sum of a field from a query |
||
377 | * |
||
378 | * @param string $field |
||
379 | * @param string|bool $as |
||
380 | * @return QueryBuilderInterface |
||
381 | */ |
||
382 | public function selectSum(string $field, $as=FALSE): QueryBuilderInterface |
||
388 | |||
389 | /** |
||
390 | * Adds the 'distinct' keyword to a query |
||
391 | * |
||
392 | * @return QueryBuilderInterface |
||
393 | */ |
||
394 | public function distinct(): QueryBuilderInterface |
||
400 | |||
401 | /** |
||
402 | * Tell the database to give you the query plan instead of result set |
||
403 | * |
||
404 | * @return QueryBuilderInterface |
||
405 | */ |
||
406 | public function explain(): QueryBuilderInterface |
||
411 | |||
412 | /** |
||
413 | * Specify the database table to select from |
||
414 | * |
||
415 | * @param string $tblname |
||
416 | * @return QueryBuilderInterface |
||
417 | */ |
||
418 | public function from($tblname): QueryBuilderInterface |
||
433 | |||
434 | // -------------------------------------------------------------------------- |
||
435 | // ! 'Like' methods |
||
436 | // -------------------------------------------------------------------------- |
||
437 | |||
438 | /** |
||
439 | * Creates a Like clause in the sql statement |
||
440 | * |
||
441 | * @param string $field |
||
442 | * @param mixed $val |
||
443 | * @param string $pos |
||
444 | * @return QueryBuilderInterface |
||
445 | */ |
||
446 | public function like($field, $val, $pos='both'): QueryBuilderInterface |
||
450 | |||
451 | /** |
||
452 | * Generates an OR Like clause |
||
453 | * |
||
454 | * @param string $field |
||
455 | * @param mixed $val |
||
456 | * @param string $pos |
||
457 | * @return QueryBuilderInterface |
||
458 | */ |
||
459 | public function orLike($field, $val, $pos='both'): QueryBuilderInterface |
||
463 | |||
464 | /** |
||
465 | * Generates a NOT LIKE clause |
||
466 | * |
||
467 | * @param string $field |
||
468 | * @param mixed $val |
||
469 | * @param string $pos |
||
470 | * @return QueryBuilderInterface |
||
471 | */ |
||
472 | public function notLike($field, $val, $pos='both'): QueryBuilderInterface |
||
476 | |||
477 | /** |
||
478 | * Generates a OR NOT LIKE clause |
||
479 | * |
||
480 | * @param string $field |
||
481 | * @param mixed $val |
||
482 | * @param string $pos |
||
483 | * @return QueryBuilderInterface |
||
484 | */ |
||
485 | public function orNotLike($field, $val, $pos='both'): QueryBuilderInterface |
||
489 | |||
490 | // -------------------------------------------------------------------------- |
||
491 | // ! Having methods |
||
492 | // -------------------------------------------------------------------------- |
||
493 | |||
494 | /** |
||
495 | * Generates a 'Having' clause |
||
496 | * |
||
497 | * @param mixed $key |
||
498 | * @param mixed $val |
||
499 | * @return QueryBuilderInterface |
||
500 | */ |
||
501 | public function having($key, $val=[]): QueryBuilderInterface |
||
505 | |||
506 | /** |
||
507 | * Generates a 'Having' clause prefixed with 'OR' |
||
508 | * |
||
509 | * @param mixed $key |
||
510 | * @param mixed $val |
||
511 | * @return QueryBuilderInterface |
||
512 | */ |
||
513 | public function orHaving($key, $val=[]): QueryBuilderInterface |
||
517 | |||
518 | // -------------------------------------------------------------------------- |
||
519 | // ! 'Where' methods |
||
520 | // -------------------------------------------------------------------------- |
||
521 | |||
522 | /** |
||
523 | * Specify condition(s) in the where clause of a query |
||
524 | * Note: this function works with key / value, or a |
||
525 | * passed array with key / value pairs |
||
526 | * |
||
527 | * @param mixed $key |
||
528 | * @param mixed $val |
||
529 | * @param mixed $escape |
||
530 | * @return QueryBuilderInterface |
||
531 | */ |
||
532 | public function where($key, $val=[], $escape=NULL): QueryBuilderInterface |
||
536 | |||
537 | /** |
||
538 | * Where clause prefixed with "OR" |
||
539 | * |
||
540 | * @param string $key |
||
541 | * @param mixed $val |
||
542 | * @return QueryBuilderInterface |
||
543 | */ |
||
544 | public function orWhere($key, $val=[]): QueryBuilderInterface |
||
548 | |||
549 | /** |
||
550 | * Where clause with 'IN' statement |
||
551 | * |
||
552 | * @param mixed $field |
||
553 | * @param mixed $val |
||
554 | * @return QueryBuilderInterface |
||
555 | */ |
||
556 | public function whereIn($field, $val=[]): QueryBuilderInterface |
||
560 | |||
561 | /** |
||
562 | * Where in statement prefixed with "or" |
||
563 | * |
||
564 | * @param string $field |
||
565 | * @param mixed $val |
||
566 | * @return QueryBuilderInterface |
||
567 | */ |
||
568 | public function orWhereIn($field, $val=[]): QueryBuilderInterface |
||
572 | |||
573 | /** |
||
574 | * WHERE NOT IN (FOO) clause |
||
575 | * |
||
576 | * @param string $field |
||
577 | * @param mixed $val |
||
578 | * @return QueryBuilderInterface |
||
579 | */ |
||
580 | public function whereNotIn($field, $val=[]): QueryBuilderInterface |
||
584 | |||
585 | /** |
||
586 | * OR WHERE NOT IN (FOO) clause |
||
587 | * |
||
588 | * @param string $field |
||
589 | * @param mixed $val |
||
590 | * @return QueryBuilderInterface |
||
591 | */ |
||
592 | public function orWhereNotIn($field, $val=[]): QueryBuilderInterface |
||
596 | |||
597 | // -------------------------------------------------------------------------- |
||
598 | // ! Other Query Modifier methods |
||
599 | // -------------------------------------------------------------------------- |
||
600 | |||
601 | /** |
||
602 | * Sets values for inserts / updates / deletes |
||
603 | * |
||
604 | * @param mixed $key |
||
605 | * @param mixed $val |
||
606 | * @return QueryBuilderInterface |
||
607 | */ |
||
608 | public function set($key, $val = NULL): QueryBuilderInterface |
||
623 | |||
624 | /** |
||
625 | * Creates a join phrase in a compiled query |
||
626 | * |
||
627 | * @param string $table |
||
628 | * @param string $condition |
||
629 | * @param string $type |
||
630 | * @return QueryBuilderInterface |
||
631 | */ |
||
632 | public function join($table, $condition, $type=''): QueryBuilderInterface |
||
648 | |||
649 | /** |
||
650 | * Group the results by the selected field(s) |
||
651 | * |
||
652 | * @param mixed $field |
||
653 | * @return QueryBuilderInterface |
||
654 | */ |
||
655 | public function groupBy($field): QueryBuilderInterface |
||
671 | |||
672 | /** |
||
673 | * Order the results by the selected field(s) |
||
674 | * |
||
675 | * @param string $field |
||
676 | * @param string $type |
||
677 | * @return QueryBuilderInterface |
||
678 | */ |
||
679 | public function orderBy($field, $type=''): QueryBuilderInterface |
||
708 | |||
709 | /** |
||
710 | * Set a limit on the current sql statement |
||
711 | * |
||
712 | * @param int $limit |
||
713 | * @param int|bool $offset |
||
714 | * @return QueryBuilderInterface |
||
715 | */ |
||
716 | public function limit($limit, $offset=FALSE): QueryBuilderInterface |
||
723 | |||
724 | // -------------------------------------------------------------------------- |
||
725 | // ! Query Grouping Methods |
||
726 | // -------------------------------------------------------------------------- |
||
727 | |||
728 | /** |
||
729 | * Adds a paren to the current query for query grouping |
||
730 | * |
||
731 | * @return QueryBuilderInterface |
||
732 | */ |
||
733 | View Code Duplication | public function groupStart(): QueryBuilderInterface |
|
741 | |||
742 | /** |
||
743 | * Adds a paren to the current query for query grouping, |
||
744 | * prefixed with 'NOT' |
||
745 | * |
||
746 | * @return QueryBuilderInterface |
||
747 | */ |
||
748 | View Code Duplication | public function notGroupStart(): QueryBuilderInterface |
|
756 | |||
757 | /** |
||
758 | * Adds a paren to the current query for query grouping, |
||
759 | * prefixed with 'OR' |
||
760 | * |
||
761 | * @return QueryBuilderInterface |
||
762 | */ |
||
763 | public function orGroupStart(): QueryBuilderInterface |
||
769 | |||
770 | /** |
||
771 | * Adds a paren to the current query for query grouping, |
||
772 | * prefixed with 'OR NOT' |
||
773 | * |
||
774 | * @return QueryBuilderInterface |
||
775 | */ |
||
776 | public function orNotGroupStart(): QueryBuilderInterface |
||
782 | |||
783 | /** |
||
784 | * Ends a query group |
||
785 | * |
||
786 | * @return QueryBuilderInterface |
||
787 | */ |
||
788 | public function groupEnd(): QueryBuilderInterface |
||
794 | |||
795 | // -------------------------------------------------------------------------- |
||
796 | // ! Query execution methods |
||
797 | // -------------------------------------------------------------------------- |
||
798 | |||
799 | /** |
||
800 | * Select and retrieve all records from the current table, and/or |
||
801 | * execute current compiled query |
||
802 | * |
||
803 | * @param string $table |
||
804 | * @param int|bool $limit |
||
805 | * @param int|bool $offset |
||
806 | * @return PDOStatement |
||
807 | */ |
||
808 | public function get($table='', $limit=FALSE, $offset=FALSE): PDOStatement |
||
824 | |||
825 | /** |
||
826 | * Convenience method for get() with a where clause |
||
827 | * |
||
828 | * @param string $table |
||
829 | * @param array $where |
||
830 | * @param int|bool $limit |
||
831 | * @param int|bool $offset |
||
832 | * @return PDOStatement |
||
833 | */ |
||
834 | public function getWhere($table, $where=[], $limit=FALSE, $offset=FALSE): PDOStatement |
||
842 | |||
843 | /** |
||
844 | * Retrieve the number of rows in the selected table |
||
845 | * |
||
846 | * @param string $table |
||
847 | * @return int |
||
848 | */ |
||
849 | public function countAll($table): int |
||
855 | |||
856 | /** |
||
857 | * Retrieve the number of results for the generated query - used |
||
858 | * in place of the get() method |
||
859 | * |
||
860 | * @param string $table |
||
861 | * @param boolean $reset |
||
862 | * @return int |
||
863 | */ |
||
864 | public function countAllResults(string $table='', bool $reset = TRUE): int |
||
877 | |||
878 | /** |
||
879 | * Creates an insert clause, and executes it |
||
880 | * |
||
881 | * @param string $table |
||
882 | * @param mixed $data |
||
883 | * @return PDOStatement |
||
884 | */ |
||
885 | public function insert($table, $data=[]): PDOStatement |
||
894 | |||
895 | /** |
||
896 | * Creates and executes a batch insertion query |
||
897 | * |
||
898 | * @param string $table |
||
899 | * @param array $data |
||
900 | * @return PDOStatement |
||
901 | */ |
||
902 | View Code Duplication | public function insertBatch($table, $data=[]): PDOStatement |
|
911 | |||
912 | /** |
||
913 | * Creates an update clause, and executes it |
||
914 | * |
||
915 | * @param string $table |
||
916 | * @param mixed $data |
||
917 | * @return PDOStatement |
||
918 | */ |
||
919 | public function update($table, $data=[]): PDOStatement |
||
928 | |||
929 | /** |
||
930 | * Creates a batch update, and executes it. |
||
931 | * Returns the number of affected rows |
||
932 | * |
||
933 | * @param string $table |
||
934 | * @param array|object $data |
||
935 | * @param string $where |
||
936 | * @return int|null |
||
937 | */ |
||
938 | View Code Duplication | public function updateBatch($table, $data, $where) |
|
947 | |||
948 | /** |
||
949 | * Insertion with automatic overwrite, rather than attempted duplication |
||
950 | * |
||
951 | * @param string $table |
||
952 | * @param array $data |
||
953 | * @return \PDOStatement|null |
||
954 | */ |
||
955 | public function replace($table, $data=[]) |
||
964 | |||
965 | /** |
||
966 | * Deletes data from a table |
||
967 | * |
||
968 | * @param string $table |
||
969 | * @param mixed $where |
||
970 | * @return PDOStatement |
||
971 | */ |
||
972 | public function delete($table, $where=''): PDOStatement |
||
982 | |||
983 | // -------------------------------------------------------------------------- |
||
984 | // ! SQL Returning Methods |
||
985 | // -------------------------------------------------------------------------- |
||
986 | |||
987 | /** |
||
988 | * Returns the generated 'select' sql query |
||
989 | * |
||
990 | * @param string $table |
||
991 | * @param bool $reset |
||
992 | * @return string |
||
993 | */ |
||
994 | public function getCompiledSelect(string $table='', bool $reset=TRUE): string |
||
1004 | |||
1005 | /** |
||
1006 | * Returns the generated 'insert' sql query |
||
1007 | * |
||
1008 | * @param string $table |
||
1009 | * @param bool $reset |
||
1010 | * @return string |
||
1011 | */ |
||
1012 | public function getCompiledInsert(string $table, bool $reset=TRUE): string |
||
1016 | |||
1017 | /** |
||
1018 | * Returns the generated 'update' sql query |
||
1019 | * |
||
1020 | * @param string $table |
||
1021 | * @param bool $reset |
||
1022 | * @return string |
||
1023 | */ |
||
1024 | public function getCompiledUpdate(string $table='', bool $reset=TRUE): string |
||
1028 | |||
1029 | /** |
||
1030 | * Returns the generated 'delete' sql query |
||
1031 | * |
||
1032 | * @param string $table |
||
1033 | * @param bool $reset |
||
1034 | * @return string |
||
1035 | */ |
||
1036 | public function getCompiledDelete(string $table='', bool $reset=TRUE): string |
||
1040 | |||
1041 | // -------------------------------------------------------------------------- |
||
1042 | // ! Miscellaneous Methods |
||
1043 | // -------------------------------------------------------------------------- |
||
1044 | |||
1045 | /** |
||
1046 | * Clear out the class variables, so the next query can be run |
||
1047 | * |
||
1048 | * @return void |
||
1049 | */ |
||
1050 | public function resetQuery(): void |
||
1064 | |||
1065 | /** |
||
1066 | * Set values in the class, with either an array or key value pair |
||
1067 | * |
||
1068 | * @param array $var |
||
1069 | * @param mixed $key |
||
1070 | * @param mixed $val |
||
1071 | * @param int $valType |
||
1072 | * @return array |
||
1073 | */ |
||
1074 | protected function _mixedSet(array &$var, $key, $val=NULL, int $valType=self::BOTH): array |
||
1096 | |||
1097 | /** |
||
1098 | * Method to simplify select_ methods |
||
1099 | * |
||
1100 | * @param string $field |
||
1101 | * @param string|bool $as |
||
1102 | * @return string |
||
1103 | */ |
||
1104 | protected function _select(string $field, $as = FALSE): string |
||
1117 | |||
1118 | /** |
||
1119 | * Helper function for returning sql strings |
||
1120 | * |
||
1121 | * @param string $type |
||
1122 | * @param string $table |
||
1123 | * @param bool $reset |
||
1124 | * @return string |
||
1125 | */ |
||
1126 | protected function _getCompile(string $type, string $table, bool $reset): string |
||
1138 | |||
1139 | /** |
||
1140 | * Simplify 'like' methods |
||
1141 | * |
||
1142 | * @param string $field |
||
1143 | * @param mixed $val |
||
1144 | * @param string $pos |
||
1145 | * @param string $like |
||
1146 | * @param string $conj |
||
1147 | * @return self |
||
1148 | */ |
||
1149 | protected function _like(string $field, $val, string $pos, string $like='LIKE', string $conj='AND'): self |
||
1177 | |||
1178 | /** |
||
1179 | * Simplify building having clauses |
||
1180 | * |
||
1181 | * @param mixed $key |
||
1182 | * @param mixed $values |
||
1183 | * @param string $conj |
||
1184 | * @return self |
||
1185 | */ |
||
1186 | protected function _having($key, $values=[], string $conj='AND'): self |
||
1211 | |||
1212 | /** |
||
1213 | * Do all the redundant stuff for where/having type methods |
||
1214 | * |
||
1215 | * @param mixed $key |
||
1216 | * @param mixed $val |
||
1217 | * @return array |
||
1218 | */ |
||
1219 | protected function _where($key, $val=[]): array |
||
1226 | |||
1227 | /** |
||
1228 | * Simplify generating where string |
||
1229 | * |
||
1230 | * @param mixed $key |
||
1231 | * @param mixed $values |
||
1232 | * @param string $defaultConj |
||
1233 | * @return self |
||
1234 | */ |
||
1235 | protected function _whereString($key, $values=[], string $defaultConj='AND'): self |
||
1270 | |||
1271 | /** |
||
1272 | * Simplify where_in methods |
||
1273 | * |
||
1274 | * @param mixed $key |
||
1275 | * @param mixed $val |
||
1276 | * @param string $in - The (not) in fragment |
||
1277 | * @param string $conj - The where in conjunction |
||
1278 | * @return self |
||
1279 | */ |
||
1280 | protected function _whereIn($key, $val=[], string $in='IN', string $conj='AND'): self |
||
1297 | |||
1298 | /** |
||
1299 | * Executes the compiled query |
||
1300 | * |
||
1301 | * @param string $type |
||
1302 | * @param string $table |
||
1303 | * @param string $sql |
||
1304 | * @param array|null $vals |
||
1305 | * @param boolean $reset |
||
1306 | * @return PDOStatement |
||
1307 | */ |
||
1308 | protected function _run(string $type, string $table, $sql=NULL, $vals=NULL, bool $reset=TRUE): PDOStatement |
||
1340 | |||
1341 | /** |
||
1342 | * Add an additional set of mapping pairs to a internal map |
||
1343 | * |
||
1344 | * @param string $conjunction |
||
1345 | * @param string $string |
||
1346 | * @param string $type |
||
1347 | * @return void |
||
1348 | */ |
||
1349 | protected function _appendMap(string $conjunction = '', string $string = '', string $type = '') |
||
1357 | |||
1358 | /** |
||
1359 | * Convert the prepared statement into readable sql |
||
1360 | * |
||
1361 | * @param array $vals |
||
1362 | * @param string $sql |
||
1363 | * @param int $totalTime |
||
1364 | * @return void |
||
1365 | */ |
||
1366 | protected function _appendQuery($vals, string $sql, int $totalTime) |
||
1394 | |||
1395 | /** |
||
1396 | * Sub-method for generating sql strings |
||
1397 | * |
||
1398 | * @param string $type |
||
1399 | * @param string $table |
||
1400 | * @return string |
||
1401 | */ |
||
1402 | protected function _compileType(string $type='', string $table=''): string |
||
1442 | |||
1443 | /** |
||
1444 | * String together the sql statements for sending to the db |
||
1445 | * |
||
1446 | * @param string $type |
||
1447 | * @param string $table |
||
1448 | * @return string |
||
1449 | */ |
||
1450 | protected function _compile(string $type='', string $table=''): string |
||
1494 | } |
||
1495 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..