Complex classes like AdvancedTrait 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 AdvancedTrait, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
15 | trait AdvancedTrait |
||
16 | { |
||
17 | /** |
||
18 | * Get argument value |
||
19 | * |
||
20 | * @param string $name |
||
21 | * |
||
22 | * @return string |
||
23 | */ |
||
24 | abstract protected function getArgumentValue($name); |
||
25 | |||
26 | /** |
||
27 | * Set argument |
||
28 | * |
||
29 | * @param string $argument |
||
30 | * |
||
31 | * @return $this |
||
32 | */ |
||
33 | abstract protected function setArgument($argument); |
||
34 | |||
35 | /** |
||
36 | * Whether ASCII85 encode pages |
||
37 | * |
||
38 | * @return bool |
||
39 | */ |
||
40 | public function isAscii85EncodePages() |
||
49 | |||
50 | /** |
||
51 | * Set ASCII85 encode pages flag |
||
52 | * |
||
53 | * @param bool $ascii85EncodePages |
||
54 | * |
||
55 | * @return $this |
||
56 | */ |
||
57 | public function setAscii85EncodePages($ascii85EncodePages) |
||
63 | |||
64 | /** |
||
65 | * Whether to auto position EPS files |
||
66 | * |
||
67 | * @return bool |
||
68 | */ |
||
69 | public function isAutoPositionEpsFiles() |
||
78 | |||
79 | /** |
||
80 | * Set auto position EPS files flag |
||
81 | * |
||
82 | * @param bool $autoPositionEpsFiles |
||
83 | * |
||
84 | * @return $this |
||
85 | */ |
||
86 | public function setAutoPositionEpsFiles($autoPositionEpsFiles) |
||
92 | |||
93 | /** |
||
94 | * Whether to create job ticket |
||
95 | * |
||
96 | * @return bool |
||
97 | */ |
||
98 | public function isCreateJobTicket() |
||
107 | |||
108 | /** |
||
109 | * Set create job ticket flag |
||
110 | * |
||
111 | * @param bool $createJobTicket |
||
112 | * |
||
113 | * @return $this |
||
114 | */ |
||
115 | public function setCreateJobTicket($createJobTicket) |
||
121 | |||
122 | /** |
||
123 | * Whether to detect blends |
||
124 | * |
||
125 | * @return bool |
||
126 | */ |
||
127 | public function isDetectBlends() |
||
136 | |||
137 | /** |
||
138 | * Set detect blends flag |
||
139 | * |
||
140 | * @param bool $detectBlends |
||
141 | * |
||
142 | * @return $this |
||
143 | */ |
||
144 | public function setDetectBlends($detectBlends) |
||
150 | |||
151 | /** |
||
152 | * Whether to emit DSC warnings |
||
153 | * |
||
154 | * @return bool |
||
155 | */ |
||
156 | public function isEmitDscWarnings() |
||
165 | |||
166 | /** |
||
167 | * Set emit DSC warnings flag |
||
168 | * |
||
169 | * @param bool $emitDscWarnings |
||
170 | * |
||
171 | * @return $this |
||
172 | */ |
||
173 | public function setEmitDscWarnings($emitDscWarnings) |
||
179 | |||
180 | /** |
||
181 | * Whether to lock distiller params |
||
182 | * |
||
183 | * @return bool |
||
184 | */ |
||
185 | public function isLockDistillerParams() |
||
194 | |||
195 | /** |
||
196 | * Set lock distiller params flag |
||
197 | * |
||
198 | * @param bool $lockDistillerParams |
||
199 | * |
||
200 | * @return $this |
||
201 | */ |
||
202 | public function setLockDistillerParams($lockDistillerParams) |
||
208 | |||
209 | /** |
||
210 | * Get OPM |
||
211 | * |
||
212 | * @return int |
||
213 | */ |
||
214 | public function getOpm() |
||
223 | |||
224 | /** |
||
225 | * Set OPM |
||
226 | * |
||
227 | * @param int $opm |
||
228 | * |
||
229 | * @return $this |
||
230 | */ |
||
231 | public function setOpm($opm) |
||
237 | |||
238 | /** |
||
239 | * Whether to parse DSC comments |
||
240 | * |
||
241 | * @return bool |
||
242 | */ |
||
243 | public function isParseDscComments() |
||
252 | |||
253 | /** |
||
254 | * Set parse DSC comments flag |
||
255 | * |
||
256 | * @param bool $parseDscComments |
||
257 | * |
||
258 | * @return $this |
||
259 | */ |
||
260 | public function setParseDscComments($parseDscComments) |
||
266 | |||
267 | /** |
||
268 | * Whether to parse DSC comments for doc info |
||
269 | * |
||
270 | * @return bool |
||
271 | */ |
||
272 | public function isParseDscCommentsForDocInfo() |
||
281 | |||
282 | /** |
||
283 | * Set parse DSC comments for doc info flag |
||
284 | * |
||
285 | * @param bool $parseDscCommentsForDocInfo |
||
286 | * |
||
287 | * @return $this |
||
288 | */ |
||
289 | public function setParseDscCommentsForDocInfo($parseDscCommentsForDocInfo) |
||
295 | |||
296 | /** |
||
297 | * Whether to preserve copy page |
||
298 | * |
||
299 | * @return bool |
||
300 | */ |
||
301 | public function isPreserveCopyPage() |
||
310 | |||
311 | /** |
||
312 | * Set preserve copy page flag |
||
313 | * |
||
314 | * @param bool $preserveCopyPage |
||
315 | * |
||
316 | * @return $this |
||
317 | */ |
||
318 | public function setPreserveCopyPage($preserveCopyPage) |
||
324 | |||
325 | /** |
||
326 | * Whether to preserve EPS info |
||
327 | * |
||
328 | * @return bool |
||
329 | */ |
||
330 | public function isPreserveEpsInfo() |
||
339 | |||
340 | /** |
||
341 | * Set preserve EPS info flag |
||
342 | * |
||
343 | * @param bool $preserveEpsInfo |
||
344 | * |
||
345 | * @return $this |
||
346 | */ |
||
347 | public function setPreserveEpsInfo($preserveEpsInfo) |
||
353 | |||
354 | /** |
||
355 | * Whether to preserve OPI comments |
||
356 | * |
||
357 | * @return bool |
||
358 | */ |
||
359 | public function isPreserveOpiComments() |
||
368 | |||
369 | /** |
||
370 | * Set preserve OPI comments flag |
||
371 | * |
||
372 | * @param bool $preserveOpiComments |
||
373 | * |
||
374 | * @return $this |
||
375 | */ |
||
376 | public function setPreserveOpiComments($preserveOpiComments) |
||
382 | |||
383 | /** |
||
384 | * Whether to use prologue |
||
385 | * |
||
386 | * @return bool |
||
387 | */ |
||
388 | public function isUsePrologue() |
||
397 | |||
398 | /** |
||
399 | * Set use prologue flag |
||
400 | * |
||
401 | * @param bool $usePrologue |
||
402 | * |
||
403 | * @return $this |
||
404 | */ |
||
405 | public function setUsePrologue($usePrologue) |
||
411 | } |
||
412 |