Complex classes like AbstractQueryBuilder 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 AbstractQueryBuilder, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
22 | abstract class AbstractQueryBuilder extends \yii\base\Object implements QueryBuilderInterface |
||
|
|||
23 | { |
||
24 | /** |
||
25 | * @var AbstractConnection |
||
26 | */ |
||
27 | public $db; |
||
28 | |||
29 | 2 | public function __construct($connection, $config = []) |
|
34 | |||
35 | /** |
||
36 | * Builds config array to create Command. |
||
37 | * @param Query $query |
||
38 | * @throws NotSupportedException |
||
39 | * @return array |
||
40 | */ |
||
41 | 2 | public function build(Query $query) |
|
45 | |||
46 | 3 | public function createRequest($query) |
|
52 | |||
53 | /** |
||
54 | * Prepares query before actual building. |
||
55 | * This function for you to redefine. |
||
56 | * It will be called before other build functions. |
||
57 | * @param Query $query |
||
58 | */ |
||
59 | 2 | public function prepare(Query $query) |
|
60 | { |
||
61 | 2 | return $query->prepare($this); |
|
62 | } |
||
63 | |||
64 | /** |
||
65 | * This function is for you to provide your authentication. |
||
66 | * @param Query $query |
||
67 | */ |
||
68 | abstract public function buildAuth(Query $query); |
||
69 | |||
70 | abstract public function buildMethod(Query $query); |
||
71 | |||
72 | abstract public function buildUri(Query $query); |
||
73 | |||
74 | abstract public function buildHeaders(Query $query); |
||
75 | |||
76 | abstract public function buildProtocolVersion(Query $query); |
||
77 | |||
78 | abstract public function buildQueryParams(Query $query); |
||
79 | |||
80 | abstract public function buildFormParams(Query $query); |
||
81 | |||
82 | abstract public function buildBody(Query $query); |
||
83 | |||
84 | /** |
||
85 | * Creates insert request. |
||
86 | * @param string $table |
||
87 | * @param array $columns |
||
88 | * @param array $options |
||
89 | * @return AbstractRequest |
||
90 | */ |
||
91 | 1 | public function insert($table, $columns, array $options = []) |
|
95 | |||
96 | /** |
||
97 | * Creates update request. |
||
98 | * @param string $table |
||
99 | * @param array $columns |
||
100 | * @param array $condition |
||
101 | * @param array $options |
||
102 | * @return AbstractRequest |
||
103 | */ |
||
104 | public function update($table, $columns, $condition = [], array $options = []) |
||
110 | |||
111 | /** |
||
112 | * Creates delete request. |
||
113 | * @param string $table |
||
114 | * @param array $condition |
||
115 | * @param array $options |
||
116 | * @return AbstractRequest |
||
117 | */ |
||
118 | public function delete($table, $condition = [], array $options = []) |
||
124 | |||
125 | /** |
||
126 | * Creates request for given action. |
||
127 | * @param string $action |
||
128 | * @param string $table |
||
129 | * @param mixed $body |
||
130 | * @param array $options |
||
131 | * @return AbstractRequest |
||
132 | */ |
||
133 | 1 | public function perform($action, $table, $body, $options = []) |
|
139 | |||
140 | 1 | public function createQuery($action, $table, array $options = []) |
|
146 | |||
147 | public function buildCondition($condition) |
||
184 | |||
185 | protected function buildHashCondition($condition) |
||
199 | |||
200 | protected function buildLikeCondition($operator, $operands) |
||
204 | |||
205 | protected function buildIlikeCondition($operator, $operands) |
||
209 | |||
210 | protected function buildCompareCondition($operator, $operands) |
||
218 | |||
219 | protected function buildAndCondition($operator, $operands) |
||
233 | |||
234 | protected function buildBetweenCondition($operator, $operands) |
||
238 | |||
239 | protected function buildInCondition($operator, $operands, $not = false) |
||
270 | |||
271 | protected function buildNotInCondition($operator, $operands) |
||
275 | |||
276 | protected function buildEqCondition($operator, $operands) |
||
282 | |||
283 | protected function buildNotEqCondition($operator, $operands) |
||
289 | |||
290 | protected function buildCompositeInCondition($operator, $columns, $values) |
||
294 | } |
||
295 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.