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 |
||
17 | trait AdvancedTrait |
||
18 | { |
||
19 | /** |
||
20 | * Get argument value |
||
21 | * |
||
22 | * @param string $name |
||
23 | * |
||
24 | * @return string |
||
25 | */ |
||
26 | abstract protected function getArgumentValue($name); |
||
27 | |||
28 | /** |
||
29 | * Set argument |
||
30 | * |
||
31 | * @param string $argument |
||
32 | * |
||
33 | * @return $this |
||
34 | */ |
||
35 | abstract protected function setArgument($argument); |
||
36 | |||
37 | /** |
||
38 | * Get PDF settings |
||
39 | * |
||
40 | * @return string |
||
41 | */ |
||
42 | abstract public function getPdfSettings(); |
||
43 | |||
44 | /** |
||
45 | * Whether ASCII85 encode pages |
||
46 | * |
||
47 | * @return bool |
||
48 | */ |
||
49 | public function isAscii85EncodePages() |
||
58 | |||
59 | /** |
||
60 | * Set ASCII85 encode pages flag |
||
61 | * |
||
62 | * @param bool $ascii85EncodePages |
||
63 | * |
||
64 | * @return $this |
||
65 | */ |
||
66 | public function setAscii85EncodePages($ascii85EncodePages) |
||
72 | |||
73 | /** |
||
74 | * Whether to auto position EPS files |
||
75 | * |
||
76 | * @return bool |
||
77 | */ |
||
78 | public function isAutoPositionEpsFiles() |
||
87 | |||
88 | /** |
||
89 | * Set auto position EPS files flag |
||
90 | * |
||
91 | * @param bool $autoPositionEpsFiles |
||
92 | * |
||
93 | * @return $this |
||
94 | */ |
||
95 | public function setAutoPositionEpsFiles($autoPositionEpsFiles) |
||
101 | |||
102 | /** |
||
103 | * Whether to create job ticket |
||
104 | * |
||
105 | * @return bool |
||
106 | */ |
||
107 | public function isCreateJobTicket() |
||
122 | |||
123 | /** |
||
124 | * Set create job ticket flag |
||
125 | * |
||
126 | * @param bool $createJobTicket |
||
127 | * |
||
128 | * @return $this |
||
129 | */ |
||
130 | public function setCreateJobTicket($createJobTicket) |
||
136 | |||
137 | /** |
||
138 | * Whether to detect blends |
||
139 | * |
||
140 | * @return bool |
||
141 | */ |
||
142 | public function isDetectBlends() |
||
151 | |||
152 | /** |
||
153 | * Set detect blends flag |
||
154 | * |
||
155 | * @param bool $detectBlends |
||
156 | * |
||
157 | * @return $this |
||
158 | */ |
||
159 | public function setDetectBlends($detectBlends) |
||
165 | |||
166 | /** |
||
167 | * Whether to emit DSC warnings |
||
168 | * |
||
169 | * @return bool |
||
170 | */ |
||
171 | public function isEmitDscWarnings() |
||
180 | |||
181 | /** |
||
182 | * Set emit DSC warnings flag |
||
183 | * |
||
184 | * @param bool $emitDscWarnings |
||
185 | * |
||
186 | * @return $this |
||
187 | */ |
||
188 | public function setEmitDscWarnings($emitDscWarnings) |
||
194 | |||
195 | /** |
||
196 | * Whether to lock distiller params |
||
197 | * |
||
198 | * @return bool |
||
199 | */ |
||
200 | public function isLockDistillerParams() |
||
209 | |||
210 | /** |
||
211 | * Set lock distiller params flag |
||
212 | * |
||
213 | * @param bool $lockDistillerParams |
||
214 | * |
||
215 | * @return $this |
||
216 | */ |
||
217 | public function setLockDistillerParams($lockDistillerParams) |
||
223 | |||
224 | /** |
||
225 | * Get OPM |
||
226 | * |
||
227 | * @return int |
||
228 | */ |
||
229 | public function getOpm() |
||
238 | |||
239 | /** |
||
240 | * Set OPM |
||
241 | * |
||
242 | * @param int $opm |
||
243 | * |
||
244 | * @return $this |
||
245 | */ |
||
246 | public function setOpm($opm) |
||
252 | |||
253 | /** |
||
254 | * Whether to parse DSC comments |
||
255 | * |
||
256 | * @return bool |
||
257 | */ |
||
258 | public function isParseDscComments() |
||
267 | |||
268 | /** |
||
269 | * Set parse DSC comments flag |
||
270 | * |
||
271 | * @param bool $parseDscComments |
||
272 | * |
||
273 | * @return $this |
||
274 | */ |
||
275 | public function setParseDscComments($parseDscComments) |
||
281 | |||
282 | /** |
||
283 | * Whether to parse DSC comments for doc info |
||
284 | * |
||
285 | * @return bool |
||
286 | */ |
||
287 | public function isParseDscCommentsForDocInfo() |
||
296 | |||
297 | /** |
||
298 | * Set parse DSC comments for doc info flag |
||
299 | * |
||
300 | * @param bool $parseDscCommentsForDocInfo |
||
301 | * |
||
302 | * @return $this |
||
303 | */ |
||
304 | public function setParseDscCommentsForDocInfo($parseDscCommentsForDocInfo) |
||
310 | |||
311 | /** |
||
312 | * Whether to preserve copy page |
||
313 | * |
||
314 | * @return bool |
||
315 | */ |
||
316 | public function isPreserveCopyPage() |
||
325 | |||
326 | /** |
||
327 | * Set preserve copy page flag |
||
328 | * |
||
329 | * @param bool $preserveCopyPage |
||
330 | * |
||
331 | * @return $this |
||
332 | */ |
||
333 | public function setPreserveCopyPage($preserveCopyPage) |
||
339 | |||
340 | /** |
||
341 | * Whether to preserve EPS info |
||
342 | * |
||
343 | * @return bool |
||
344 | */ |
||
345 | public function isPreserveEpsInfo() |
||
354 | |||
355 | /** |
||
356 | * Set preserve EPS info flag |
||
357 | * |
||
358 | * @param bool $preserveEpsInfo |
||
359 | * |
||
360 | * @return $this |
||
361 | */ |
||
362 | public function setPreserveEpsInfo($preserveEpsInfo) |
||
368 | |||
369 | /** |
||
370 | * Whether to preserve OPI comments |
||
371 | * |
||
372 | * @return bool |
||
373 | */ |
||
374 | public function isPreserveOpiComments() |
||
389 | |||
390 | /** |
||
391 | * Set preserve OPI comments flag |
||
392 | * |
||
393 | * @param bool $preserveOpiComments |
||
394 | * |
||
395 | * @return $this |
||
396 | */ |
||
397 | public function setPreserveOpiComments($preserveOpiComments) |
||
403 | |||
404 | /** |
||
405 | * Whether to use prologue |
||
406 | * |
||
407 | * @return bool |
||
408 | */ |
||
409 | public function isUsePrologue() |
||
418 | |||
419 | /** |
||
420 | * Set use prologue flag |
||
421 | * |
||
422 | * @param bool $usePrologue |
||
423 | * |
||
424 | * @return $this |
||
425 | */ |
||
426 | public function setUsePrologue($usePrologue) |
||
432 | } |
||
433 |