Complex classes like OracleGrammar 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 OracleGrammar, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
9 | class OracleGrammar extends Grammar |
||
10 | { |
||
11 | /** |
||
12 | * The keyword identifier wrapper format. |
||
13 | * |
||
14 | * @var string |
||
15 | */ |
||
16 | protected $wrapper = '%s'; |
||
17 | |||
18 | /** |
||
19 | * Compile an exists statement into SQL. |
||
20 | * |
||
21 | * @param \Illuminate\Database\Query\Builder $query |
||
22 | * @return string |
||
23 | */ |
||
24 | public function compileExists(Builder $query) |
||
33 | |||
34 | /** |
||
35 | * Compile a select query into SQL. |
||
36 | * |
||
37 | * @param \Illuminate\Database\Query\Builder |
||
38 | * @return string |
||
39 | */ |
||
40 | public function compileSelect(Builder $query) |
||
57 | |||
58 | /** |
||
59 | * @param Builder $query |
||
60 | * @param array $components |
||
61 | * @return bool |
||
62 | */ |
||
63 | protected function isPaginationable(Builder $query, array $components) |
||
67 | |||
68 | /** |
||
69 | * Create a full ANSI offset clause for the query. |
||
70 | * |
||
71 | * @param \Illuminate\Database\Query\Builder $query |
||
72 | * @param array $components |
||
73 | * @return string |
||
74 | */ |
||
75 | protected function compileAnsiOffset(Builder $query, $components) |
||
88 | |||
89 | /** |
||
90 | * Compile the limit / offset row constraint for a query. |
||
91 | * |
||
92 | * @param \Illuminate\Database\Query\Builder $query |
||
93 | * @return string |
||
94 | */ |
||
95 | protected function compileRowConstraint($query) |
||
111 | |||
112 | /** |
||
113 | * Compile a common table expression for a query. |
||
114 | * |
||
115 | * @param string $sql |
||
116 | * @param string $constraint |
||
117 | * @param Builder $query |
||
118 | * @return string |
||
119 | */ |
||
120 | protected function compileTableExpression($sql, $constraint, $query) |
||
128 | |||
129 | /** |
||
130 | * Compile a truncate table statement into SQL. |
||
131 | * |
||
132 | * @param \Illuminate\Database\Query\Builder $query |
||
133 | * @return array |
||
134 | */ |
||
135 | public function compileTruncate(Builder $query) |
||
139 | |||
140 | /** |
||
141 | * Compile an insert and get ID statement into SQL. |
||
142 | * |
||
143 | * @param \Illuminate\Database\Query\Builder $query |
||
144 | * @param array $values |
||
145 | * @param string $sequence |
||
146 | * @return string |
||
147 | */ |
||
148 | public function compileInsertGetId(Builder $query, $values, $sequence = 'id') |
||
156 | |||
157 | /** |
||
158 | * Compile an insert statement into SQL. |
||
159 | * |
||
160 | * @param \Illuminate\Database\Query\Builder $query |
||
161 | * @param array $values |
||
162 | * @return string |
||
163 | */ |
||
164 | public function compileInsert(Builder $query, array $values) |
||
199 | |||
200 | /** |
||
201 | * Compile an insert with blob field statement into SQL. |
||
202 | * |
||
203 | * @param \Illuminate\Database\Query\Builder $query |
||
204 | * @param array $values |
||
205 | * @param array $binaries |
||
206 | * @param string $sequence |
||
207 | * @return string |
||
208 | */ |
||
209 | public function compileInsertLob(Builder $query, $values, $binaries, $sequence = 'id') |
||
240 | |||
241 | /** |
||
242 | * Compile an update statement into SQL. |
||
243 | * |
||
244 | * @param \Illuminate\Database\Query\Builder $query |
||
245 | * @param array $values |
||
246 | * @param array $binaries |
||
247 | * @param string $sequence |
||
248 | * @return string |
||
249 | */ |
||
250 | public function compileUpdateLob(Builder $query, array $values, array $binaries, $sequence = 'id') |
||
299 | |||
300 | /** |
||
301 | * Compile the lock into SQL. |
||
302 | * |
||
303 | * @param \Illuminate\Database\Query\Builder $query |
||
304 | * @param bool|string $value |
||
305 | * @return string |
||
306 | * @throws Oci8Exception |
||
307 | */ |
||
308 | protected function compileLock(Builder $query, $value) |
||
320 | |||
321 | /** |
||
322 | * Compile the "limit" portions of the query. |
||
323 | * |
||
324 | * @param \Illuminate\Database\Query\Builder $query |
||
325 | * @param int $limit |
||
326 | * @return string |
||
327 | */ |
||
328 | protected function compileLimit(Builder $query, $limit) |
||
332 | |||
333 | /** |
||
334 | * Compile the "offset" portions of the query. |
||
335 | * |
||
336 | * @param \Illuminate\Database\Query\Builder $query |
||
337 | * @param int $offset |
||
338 | * @return string |
||
339 | */ |
||
340 | protected function compileOffset(Builder $query, $offset) |
||
344 | |||
345 | /** |
||
346 | * Compile a "where date" clause. |
||
347 | * |
||
348 | * @param \Illuminate\Database\Query\Builder $query |
||
349 | * @param array $where |
||
350 | * @return string |
||
351 | */ |
||
352 | protected function whereDate(Builder $query, $where) |
||
358 | |||
359 | /** |
||
360 | * Compile a date based where clause. |
||
361 | * |
||
362 | * @param string $type |
||
363 | * @param \Illuminate\Database\Query\Builder $query |
||
364 | * @param array $where |
||
365 | * @return string |
||
366 | */ |
||
367 | protected function dateBasedWhere($type, Builder $query, $where) |
||
373 | |||
374 | /** |
||
375 | * Wrap a single string in keyword identifiers. |
||
376 | * |
||
377 | * @param string $value |
||
378 | * @return string |
||
379 | */ |
||
380 | protected function wrapValue($value) |
||
384 | } |
||
385 |