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); |
||
28 | class QueryBuilder implements QueryBuilderInterface { |
||
29 | |||
30 | // -------------------------------------------------------------------------- |
||
31 | // ! Constants |
||
32 | // -------------------------------------------------------------------------- |
||
33 | |||
34 | const KEY = 0; |
||
35 | const VALUE = 1; |
||
36 | const BOTH = 2; |
||
37 | |||
38 | // -------------------------------------------------------------------------- |
||
39 | // ! SQL Clause Strings |
||
40 | // -------------------------------------------------------------------------- |
||
41 | |||
42 | /** |
||
43 | * Compiled 'select' clause |
||
44 | * @var string |
||
45 | */ |
||
46 | protected $selectString = ''; |
||
47 | |||
48 | /** |
||
49 | * Compiled 'from' clause |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $fromString = ''; |
||
53 | |||
54 | /** |
||
55 | * Compiled arguments for insert / update |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $setString; |
||
59 | |||
60 | /** |
||
61 | * Order by clause |
||
62 | * @var string |
||
63 | */ |
||
64 | protected $orderString; |
||
65 | |||
66 | /** |
||
67 | * Group by clause |
||
68 | * @var string |
||
69 | */ |
||
70 | protected $groupString; |
||
71 | |||
72 | // -------------------------------------------------------------------------- |
||
73 | // ! SQL Clause Arrays |
||
74 | // -------------------------------------------------------------------------- |
||
75 | |||
76 | /** |
||
77 | * Keys for insert/update statement |
||
78 | * @var array |
||
79 | */ |
||
80 | protected $setArrayKeys = []; |
||
81 | |||
82 | /** |
||
83 | * Key/val pairs for order by clause |
||
84 | * @var array |
||
85 | */ |
||
86 | protected $orderArray = []; |
||
87 | |||
88 | /** |
||
89 | * Key/val pairs for group by clause |
||
90 | * @var array |
||
91 | */ |
||
92 | protected $groupArray = []; |
||
93 | |||
94 | // -------------------------------------------------------------------------- |
||
95 | // ! Other Class vars |
||
96 | // -------------------------------------------------------------------------- |
||
97 | |||
98 | /** |
||
99 | * Values to apply to prepared statements |
||
100 | * @var array |
||
101 | */ |
||
102 | protected $values = []; |
||
103 | |||
104 | /** |
||
105 | * Values to apply to where clauses in prepared statements |
||
106 | * @var array |
||
107 | */ |
||
108 | protected $whereValues = []; |
||
109 | |||
110 | /** |
||
111 | * Value for limit string |
||
112 | * @var string |
||
113 | */ |
||
114 | protected $limit; |
||
115 | |||
116 | /** |
||
117 | * Value for offset in limit string |
||
118 | * @var integer |
||
119 | */ |
||
120 | protected $offset; |
||
121 | |||
122 | /** |
||
123 | * Query component order mapping |
||
124 | * for complex select queries |
||
125 | * |
||
126 | * Format: |
||
127 | * array( |
||
128 | * 'type' => 'where', |
||
129 | * 'conjunction' => ' AND ', |
||
130 | * 'string' => 'k=?' |
||
131 | * ) |
||
132 | * |
||
133 | * @var array |
||
134 | */ |
||
135 | protected $queryMap = []; |
||
136 | |||
137 | /** |
||
138 | * Map for having clause |
||
139 | * @var array |
||
140 | */ |
||
141 | protected $havingMap; |
||
142 | |||
143 | /** |
||
144 | * Convenience property for connection management |
||
145 | * @var string |
||
146 | */ |
||
147 | public $connName = ''; |
||
148 | |||
149 | /** |
||
150 | * List of queries executed |
||
151 | * @var array |
||
152 | */ |
||
153 | public $queries; |
||
154 | |||
155 | /** |
||
156 | * Whether to do only an explain on the query |
||
157 | * @var boolean |
||
158 | */ |
||
159 | protected $explain; |
||
160 | |||
161 | /** |
||
162 | * The current database driver |
||
163 | * @var DriverInterface |
||
164 | */ |
||
165 | public $driver; |
||
166 | |||
167 | /** |
||
168 | * Query parser class instance |
||
169 | * @var QueryParser |
||
170 | */ |
||
171 | protected $parser; |
||
172 | |||
173 | /** |
||
174 | * Alias to driver util class |
||
175 | * @var AbstractUtil |
||
176 | */ |
||
177 | protected $util; |
||
178 | |||
179 | /** |
||
180 | * Alias to driver sql class |
||
181 | * @var SQLInterface |
||
182 | */ |
||
183 | protected $sql; |
||
184 | |||
185 | /** |
||
186 | * String class values to be reset |
||
187 | * |
||
188 | * @var array |
||
189 | */ |
||
190 | private $stringVars = [ |
||
191 | 'selectString', |
||
192 | 'fromString', |
||
193 | 'setString', |
||
194 | 'orderString', |
||
195 | 'groupString', |
||
196 | 'limit', |
||
197 | 'offset', |
||
198 | 'explain', |
||
199 | ]; |
||
200 | |||
201 | /** |
||
202 | * Array class variables to be reset |
||
203 | * |
||
204 | * @var array |
||
205 | */ |
||
206 | private $arrayVars = [ |
||
207 | 'setArrayKeys', |
||
208 | 'orderArray', |
||
209 | 'groupArray', |
||
210 | 'values', |
||
211 | 'whereValues', |
||
212 | 'queryMap', |
||
213 | 'havingMap' |
||
214 | ]; |
||
215 | |||
216 | // -------------------------------------------------------------------------- |
||
217 | // ! Methods |
||
218 | // -------------------------------------------------------------------------- |
||
219 | |||
220 | /** |
||
221 | * Constructor |
||
222 | * |
||
223 | * @param DriverInterface $driver |
||
224 | * @param QueryParser $parser |
||
225 | */ |
||
226 | public function __construct(DriverInterface $driver, QueryParser $parser) |
||
238 | |||
239 | /** |
||
240 | * Destructor |
||
241 | * @codeCoverageIgnore |
||
242 | */ |
||
243 | public function __destruct() |
||
247 | |||
248 | /** |
||
249 | * Calls a function further down the inheritance chain |
||
250 | * |
||
251 | * @param string $name |
||
252 | * @param array $params |
||
253 | * @return mixed |
||
254 | * @throws BadMethodCallException |
||
255 | */ |
||
256 | public function __call(string $name, array $params) |
||
275 | |||
276 | // -------------------------------------------------------------------------- |
||
277 | // ! Select Queries |
||
278 | // -------------------------------------------------------------------------- |
||
279 | |||
280 | /** |
||
281 | * Specifies rows to select in a query |
||
282 | * |
||
283 | * @param string $fields |
||
284 | * @return QueryBuilderInterface |
||
285 | */ |
||
286 | public function select(string $fields): QueryBuilderInterface |
||
322 | |||
323 | /** |
||
324 | * Selects the maximum value of a field from a query |
||
325 | * |
||
326 | * @param string $field |
||
327 | * @param string|bool $as |
||
328 | * @return QueryBuilderInterface |
||
329 | */ |
||
330 | public function selectMax(string $field, $as=FALSE): QueryBuilderInterface |
||
336 | |||
337 | /** |
||
338 | * Selects the minimum value of a field from a query |
||
339 | * |
||
340 | * @param string $field |
||
341 | * @param string|bool $as |
||
342 | * @return QueryBuilderInterface |
||
343 | */ |
||
344 | public function selectMin(string $field, $as=FALSE): QueryBuilderInterface |
||
350 | |||
351 | /** |
||
352 | * Selects the average value of a field from a query |
||
353 | * |
||
354 | * @param string $field |
||
355 | * @param string|bool $as |
||
356 | * @return QueryBuilderInterface |
||
357 | */ |
||
358 | public function selectAvg(string $field, $as=FALSE): QueryBuilderInterface |
||
364 | |||
365 | /** |
||
366 | * Selects the sum of a field from a query |
||
367 | * |
||
368 | * @param string $field |
||
369 | * @param string|bool $as |
||
370 | * @return QueryBuilderInterface |
||
371 | */ |
||
372 | public function selectSum(string $field, $as=FALSE): QueryBuilderInterface |
||
378 | |||
379 | /** |
||
380 | * Adds the 'distinct' keyword to a query |
||
381 | * |
||
382 | * @return QueryBuilderInterface |
||
383 | */ |
||
384 | public function distinct(): QueryBuilderInterface |
||
390 | |||
391 | /** |
||
392 | * Tell the database to give you the query plan instead of result set |
||
393 | * |
||
394 | * @return QueryBuilderInterface |
||
395 | */ |
||
396 | public function explain(): QueryBuilderInterface |
||
401 | |||
402 | /** |
||
403 | * Specify the database table to select from |
||
404 | * |
||
405 | * @param string $tblname |
||
406 | * @return QueryBuilderInterface |
||
407 | */ |
||
408 | public function from($tblname): QueryBuilderInterface |
||
423 | |||
424 | // -------------------------------------------------------------------------- |
||
425 | // ! 'Like' methods |
||
426 | // -------------------------------------------------------------------------- |
||
427 | |||
428 | /** |
||
429 | * Creates a Like clause in the sql statement |
||
430 | * |
||
431 | * @param string $field |
||
432 | * @param mixed $val |
||
433 | * @param string $pos |
||
434 | * @return QueryBuilderInterface |
||
435 | */ |
||
436 | public function like($field, $val, $pos='both'): QueryBuilderInterface |
||
440 | |||
441 | /** |
||
442 | * Generates an OR Like clause |
||
443 | * |
||
444 | * @param string $field |
||
445 | * @param mixed $val |
||
446 | * @param string $pos |
||
447 | * @return QueryBuilderInterface |
||
448 | */ |
||
449 | public function orLike($field, $val, $pos='both'): QueryBuilderInterface |
||
453 | |||
454 | /** |
||
455 | * Generates a NOT LIKE clause |
||
456 | * |
||
457 | * @param string $field |
||
458 | * @param mixed $val |
||
459 | * @param string $pos |
||
460 | * @return QueryBuilderInterface |
||
461 | */ |
||
462 | public function notLike($field, $val, $pos='both'): QueryBuilderInterface |
||
466 | |||
467 | /** |
||
468 | * Generates a OR NOT LIKE clause |
||
469 | * |
||
470 | * @param string $field |
||
471 | * @param mixed $val |
||
472 | * @param string $pos |
||
473 | * @return QueryBuilderInterface |
||
474 | */ |
||
475 | public function orNotLike($field, $val, $pos='both'): QueryBuilderInterface |
||
479 | |||
480 | // -------------------------------------------------------------------------- |
||
481 | // ! Having methods |
||
482 | // -------------------------------------------------------------------------- |
||
483 | |||
484 | /** |
||
485 | * Generates a 'Having' clause |
||
486 | * |
||
487 | * @param mixed $key |
||
488 | * @param mixed $val |
||
489 | * @return QueryBuilderInterface |
||
490 | */ |
||
491 | public function having($key, $val=[]): QueryBuilderInterface |
||
495 | |||
496 | /** |
||
497 | * Generates a 'Having' clause prefixed with 'OR' |
||
498 | * |
||
499 | * @param mixed $key |
||
500 | * @param mixed $val |
||
501 | * @return QueryBuilderInterface |
||
502 | */ |
||
503 | public function orHaving($key, $val=[]): QueryBuilderInterface |
||
507 | |||
508 | // -------------------------------------------------------------------------- |
||
509 | // ! 'Where' methods |
||
510 | // -------------------------------------------------------------------------- |
||
511 | |||
512 | /** |
||
513 | * Specify condition(s) in the where clause of a query |
||
514 | * Note: this function works with key / value, or a |
||
515 | * passed array with key / value pairs |
||
516 | * |
||
517 | * @param mixed $key |
||
518 | * @param mixed $val |
||
519 | * @param mixed $escape |
||
520 | * @return QueryBuilderInterface |
||
521 | */ |
||
522 | public function where($key, $val=[], $escape=NULL): QueryBuilderInterface |
||
526 | |||
527 | /** |
||
528 | * Where clause prefixed with "OR" |
||
529 | * |
||
530 | * @param string $key |
||
531 | * @param mixed $val |
||
532 | * @return QueryBuilderInterface |
||
533 | */ |
||
534 | public function orWhere($key, $val=[]): QueryBuilderInterface |
||
538 | |||
539 | /** |
||
540 | * Where clause with 'IN' statement |
||
541 | * |
||
542 | * @param mixed $field |
||
543 | * @param mixed $val |
||
544 | * @return QueryBuilderInterface |
||
545 | */ |
||
546 | public function whereIn($field, $val=[]): QueryBuilderInterface |
||
550 | |||
551 | /** |
||
552 | * Where in statement prefixed with "or" |
||
553 | * |
||
554 | * @param string $field |
||
555 | * @param mixed $val |
||
556 | * @return QueryBuilderInterface |
||
557 | */ |
||
558 | public function orWhereIn($field, $val=[]): QueryBuilderInterface |
||
562 | |||
563 | /** |
||
564 | * WHERE NOT IN (FOO) clause |
||
565 | * |
||
566 | * @param string $field |
||
567 | * @param mixed $val |
||
568 | * @return QueryBuilderInterface |
||
569 | */ |
||
570 | public function whereNotIn($field, $val=[]): QueryBuilderInterface |
||
574 | |||
575 | /** |
||
576 | * OR WHERE NOT IN (FOO) clause |
||
577 | * |
||
578 | * @param string $field |
||
579 | * @param mixed $val |
||
580 | * @return QueryBuilderInterface |
||
581 | */ |
||
582 | public function orWhereNotIn($field, $val=[]): QueryBuilderInterface |
||
586 | |||
587 | // -------------------------------------------------------------------------- |
||
588 | // ! Other Query Modifier methods |
||
589 | // -------------------------------------------------------------------------- |
||
590 | |||
591 | /** |
||
592 | * Sets values for inserts / updates / deletes |
||
593 | * |
||
594 | * @param mixed $key |
||
595 | * @param mixed $val |
||
596 | * @return QueryBuilderInterface |
||
597 | */ |
||
598 | public function set($key, $val = NULL): QueryBuilderInterface |
||
613 | |||
614 | /** |
||
615 | * Creates a join phrase in a compiled query |
||
616 | * |
||
617 | * @param string $table |
||
618 | * @param string $condition |
||
619 | * @param string $type |
||
620 | * @return QueryBuilderInterface |
||
621 | */ |
||
622 | public function join($table, $condition, $type=''): QueryBuilderInterface |
||
638 | |||
639 | /** |
||
640 | * Group the results by the selected field(s) |
||
641 | * |
||
642 | * @param mixed $field |
||
643 | * @return QueryBuilderInterface |
||
644 | */ |
||
645 | public function groupBy($field): QueryBuilderInterface |
||
661 | |||
662 | /** |
||
663 | * Order the results by the selected field(s) |
||
664 | * |
||
665 | * @param string $field |
||
666 | * @param string $type |
||
667 | * @return QueryBuilderInterface |
||
668 | */ |
||
669 | public function orderBy($field, $type=''): QueryBuilderInterface |
||
698 | |||
699 | /** |
||
700 | * Set a limit on the current sql statement |
||
701 | * |
||
702 | * @param int $limit |
||
703 | * @param int|bool $offset |
||
704 | * @return QueryBuilderInterface |
||
705 | */ |
||
706 | public function limit($limit, $offset=FALSE): QueryBuilderInterface |
||
713 | |||
714 | // -------------------------------------------------------------------------- |
||
715 | // ! Query Grouping Methods |
||
716 | // -------------------------------------------------------------------------- |
||
717 | |||
718 | /** |
||
719 | * Adds a paren to the current query for query grouping |
||
720 | * |
||
721 | * @return QueryBuilderInterface |
||
722 | */ |
||
723 | View Code Duplication | public function groupStart(): QueryBuilderInterface |
|
731 | |||
732 | /** |
||
733 | * Adds a paren to the current query for query grouping, |
||
734 | * prefixed with 'NOT' |
||
735 | * |
||
736 | * @return QueryBuilderInterface |
||
737 | */ |
||
738 | View Code Duplication | public function notGroupStart(): QueryBuilderInterface |
|
746 | |||
747 | /** |
||
748 | * Adds a paren to the current query for query grouping, |
||
749 | * prefixed with 'OR' |
||
750 | * |
||
751 | * @return QueryBuilderInterface |
||
752 | */ |
||
753 | public function orGroupStart(): QueryBuilderInterface |
||
759 | |||
760 | /** |
||
761 | * Adds a paren to the current query for query grouping, |
||
762 | * prefixed with 'OR NOT' |
||
763 | * |
||
764 | * @return QueryBuilderInterface |
||
765 | */ |
||
766 | public function orNotGroupStart(): QueryBuilderInterface |
||
772 | |||
773 | /** |
||
774 | * Ends a query group |
||
775 | * |
||
776 | * @return QueryBuilderInterface |
||
777 | */ |
||
778 | public function groupEnd(): QueryBuilderInterface |
||
784 | |||
785 | // -------------------------------------------------------------------------- |
||
786 | // ! Query execution methods |
||
787 | // -------------------------------------------------------------------------- |
||
788 | |||
789 | /** |
||
790 | * Select and retrieve all records from the current table, and/or |
||
791 | * execute current compiled query |
||
792 | * |
||
793 | * @param string $table |
||
794 | * @param int|bool $limit |
||
795 | * @param int|bool $offset |
||
796 | * @return PDOStatement |
||
797 | */ |
||
798 | public function get($table='', $limit=FALSE, $offset=FALSE): PDOStatement |
||
814 | |||
815 | /** |
||
816 | * Convenience method for get() with a where clause |
||
817 | * |
||
818 | * @param string $table |
||
819 | * @param array $where |
||
820 | * @param int|bool $limit |
||
821 | * @param int|bool $offset |
||
822 | * @return PDOStatement |
||
823 | */ |
||
824 | public function getWhere($table, $where=[], $limit=FALSE, $offset=FALSE): PDOStatement |
||
832 | |||
833 | /** |
||
834 | * Retrieve the number of rows in the selected table |
||
835 | * |
||
836 | * @param string $table |
||
837 | * @return int |
||
838 | */ |
||
839 | public function countAll($table): int |
||
845 | |||
846 | /** |
||
847 | * Retrieve the number of results for the generated query - used |
||
848 | * in place of the get() method |
||
849 | * |
||
850 | * @param string $table |
||
851 | * @param boolean $reset |
||
852 | * @return int |
||
853 | */ |
||
854 | public function countAllResults(string $table='', bool $reset = TRUE): int |
||
867 | |||
868 | /** |
||
869 | * Creates an insert clause, and executes it |
||
870 | * |
||
871 | * @param string $table |
||
872 | * @param mixed $data |
||
873 | * @return PDOStatement |
||
874 | */ |
||
875 | public function insert($table, $data=[]): PDOStatement |
||
884 | |||
885 | /** |
||
886 | * Creates and executes a batch insertion query |
||
887 | * |
||
888 | * @param string $table |
||
889 | * @param array $data |
||
890 | * @return PDOStatement |
||
891 | */ |
||
892 | View Code Duplication | public function insertBatch($table, $data=[]): PDOStatement |
|
901 | |||
902 | /** |
||
903 | * Creates an update clause, and executes it |
||
904 | * |
||
905 | * @param string $table |
||
906 | * @param mixed $data |
||
907 | * @return PDOStatement |
||
908 | */ |
||
909 | public function update($table, $data=[]): PDOStatement |
||
918 | |||
919 | /** |
||
920 | * Creates a batch update, and executes it. |
||
921 | * Returns the number of affected rows |
||
922 | * |
||
923 | * @param string $table |
||
924 | * @param array|object $data |
||
925 | * @param string $where |
||
926 | * @return int|null |
||
927 | */ |
||
928 | View Code Duplication | public function updateBatch($table, $data, $where) |
|
937 | |||
938 | /** |
||
939 | * Insertion with automatic overwrite, rather than attempted duplication |
||
940 | * |
||
941 | * @param string $table |
||
942 | * @param array $data |
||
943 | * @return \PDOStatement|null |
||
944 | */ |
||
945 | public function replace($table, $data=[]) |
||
954 | |||
955 | /** |
||
956 | * Deletes data from a table |
||
957 | * |
||
958 | * @param string $table |
||
959 | * @param mixed $where |
||
960 | * @return PDOStatement |
||
961 | */ |
||
962 | public function delete($table, $where=''): PDOStatement |
||
972 | |||
973 | // -------------------------------------------------------------------------- |
||
974 | // ! SQL Returning Methods |
||
975 | // -------------------------------------------------------------------------- |
||
976 | |||
977 | /** |
||
978 | * Returns the generated 'select' sql query |
||
979 | * |
||
980 | * @param string $table |
||
981 | * @param bool $reset |
||
982 | * @return string |
||
983 | */ |
||
984 | public function getCompiledSelect(string $table='', bool $reset=TRUE): string |
||
994 | |||
995 | /** |
||
996 | * Returns the generated 'insert' sql query |
||
997 | * |
||
998 | * @param string $table |
||
999 | * @param bool $reset |
||
1000 | * @return string |
||
1001 | */ |
||
1002 | public function getCompiledInsert(string $table, bool $reset=TRUE): string |
||
1006 | |||
1007 | /** |
||
1008 | * Returns the generated 'update' sql query |
||
1009 | * |
||
1010 | * @param string $table |
||
1011 | * @param bool $reset |
||
1012 | * @return string |
||
1013 | */ |
||
1014 | public function getCompiledUpdate(string $table='', bool $reset=TRUE): string |
||
1018 | |||
1019 | /** |
||
1020 | * Returns the generated 'delete' sql query |
||
1021 | * |
||
1022 | * @param string $table |
||
1023 | * @param bool $reset |
||
1024 | * @return string |
||
1025 | */ |
||
1026 | public function getCompiledDelete(string $table='', bool $reset=TRUE): string |
||
1030 | |||
1031 | // -------------------------------------------------------------------------- |
||
1032 | // ! Miscellaneous Methods |
||
1033 | // -------------------------------------------------------------------------- |
||
1034 | |||
1035 | /** |
||
1036 | * Clear out the class variables, so the next query can be run |
||
1037 | * |
||
1038 | * @return void |
||
1039 | */ |
||
1040 | public function resetQuery(): void |
||
1054 | |||
1055 | /** |
||
1056 | * Set values in the class, with either an array or key value pair |
||
1057 | * |
||
1058 | * @param array $var |
||
1059 | * @param mixed $key |
||
1060 | * @param mixed $val |
||
1061 | * @param int $valType |
||
1062 | * @return array |
||
1063 | */ |
||
1064 | protected function _mixedSet(array &$var, $key, $val=NULL, int $valType=self::BOTH): array |
||
1086 | |||
1087 | /** |
||
1088 | * Method to simplify select_ methods |
||
1089 | * |
||
1090 | * @param string $field |
||
1091 | * @param string|bool $as |
||
1092 | * @return string |
||
1093 | */ |
||
1094 | protected function _select(string $field, $as = FALSE): string |
||
1107 | |||
1108 | /** |
||
1109 | * Helper function for returning sql strings |
||
1110 | * |
||
1111 | * @param string $type |
||
1112 | * @param string $table |
||
1113 | * @param bool $reset |
||
1114 | * @return string |
||
1115 | */ |
||
1116 | protected function _getCompile(string $type, string $table, bool $reset): string |
||
1128 | |||
1129 | /** |
||
1130 | * Simplify 'like' methods |
||
1131 | * |
||
1132 | * @param string $field |
||
1133 | * @param mixed $val |
||
1134 | * @param string $pos |
||
1135 | * @param string $like |
||
1136 | * @param string $conj |
||
1137 | * @return self |
||
1138 | */ |
||
1139 | protected function _like(string $field, $val, string $pos, string $like='LIKE', string $conj='AND'): self |
||
1167 | |||
1168 | /** |
||
1169 | * Simplify building having clauses |
||
1170 | * |
||
1171 | * @param mixed $key |
||
1172 | * @param mixed $values |
||
1173 | * @param string $conj |
||
1174 | * @return self |
||
1175 | */ |
||
1176 | protected function _having($key, $values=[], string $conj='AND'): self |
||
1201 | |||
1202 | /** |
||
1203 | * Do all the redundant stuff for where/having type methods |
||
1204 | * |
||
1205 | * @param mixed $key |
||
1206 | * @param mixed $val |
||
1207 | * @return array |
||
1208 | */ |
||
1209 | protected function _where($key, $val=[]): array |
||
1216 | |||
1217 | /** |
||
1218 | * Simplify generating where string |
||
1219 | * |
||
1220 | * @param mixed $key |
||
1221 | * @param mixed $values |
||
1222 | * @param string $defaultConj |
||
1223 | * @return self |
||
1224 | */ |
||
1225 | protected function _whereString($key, $values=[], string $defaultConj='AND'): self |
||
1260 | |||
1261 | /** |
||
1262 | * Simplify where_in methods |
||
1263 | * |
||
1264 | * @param mixed $key |
||
1265 | * @param mixed $val |
||
1266 | * @param string $in - The (not) in fragment |
||
1267 | * @param string $conj - The where in conjunction |
||
1268 | * @return self |
||
1269 | */ |
||
1270 | protected function _whereIn($key, $val=[], string $in='IN', string $conj='AND'): self |
||
1287 | |||
1288 | /** |
||
1289 | * Executes the compiled query |
||
1290 | * |
||
1291 | * @param string $type |
||
1292 | * @param string $table |
||
1293 | * @param string $sql |
||
1294 | * @param array|null $vals |
||
1295 | * @param boolean $reset |
||
1296 | * @return PDOStatement |
||
1297 | */ |
||
1298 | protected function _run(string $type, string $table, $sql=NULL, $vals=NULL, bool $reset=TRUE): PDOStatement |
||
1330 | |||
1331 | /** |
||
1332 | * Add an additional set of mapping pairs to a internal map |
||
1333 | * |
||
1334 | * @param string $conjunction |
||
1335 | * @param string $string |
||
1336 | * @param string $type |
||
1337 | * @return void |
||
1338 | */ |
||
1339 | protected function _appendMap(string $conjunction = '', string $string = '', string $type = '') |
||
1347 | |||
1348 | /** |
||
1349 | * Convert the prepared statement into readable sql |
||
1350 | * |
||
1351 | * @param array $vals |
||
1352 | * @param string $sql |
||
1353 | * @param int $totalTime |
||
1354 | * @return void |
||
1355 | */ |
||
1356 | protected function _appendQuery($vals, string $sql, int $totalTime) |
||
1384 | |||
1385 | /** |
||
1386 | * Sub-method for generating sql strings |
||
1387 | * |
||
1388 | * @param string $type |
||
1389 | * @param string $table |
||
1390 | * @return string |
||
1391 | */ |
||
1392 | protected function _compileType(string $type='', string $table=''): string |
||
1432 | |||
1433 | /** |
||
1434 | * String together the sql statements for sending to the db |
||
1435 | * |
||
1436 | * @param string $type |
||
1437 | * @param string $table |
||
1438 | * @return string |
||
1439 | */ |
||
1440 | protected function _compile(string $type='', string $table=''): string |
||
1484 | } |
||
1485 |
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..