Complex classes like Exif 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 Exif, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
43 | class Exif implements ExifInterface |
||
44 | { |
||
45 | /** |
||
46 | * @var Aperture |
||
47 | */ |
||
48 | protected $aperture; |
||
49 | |||
50 | /** |
||
51 | * @var Author |
||
52 | */ |
||
53 | protected $author; |
||
54 | |||
55 | /** |
||
56 | * @var Caption |
||
57 | */ |
||
58 | protected $caption; |
||
59 | |||
60 | /** |
||
61 | * @var Copyright |
||
62 | */ |
||
63 | protected $copyright; |
||
64 | |||
65 | /** |
||
66 | * @var Credit |
||
67 | */ |
||
68 | protected $credit; |
||
69 | |||
70 | /** |
||
71 | * @var ExposureTime |
||
72 | */ |
||
73 | protected $exposureTime; |
||
74 | |||
75 | /** |
||
76 | * @var Filename |
||
77 | */ |
||
78 | protected $filename; |
||
79 | |||
80 | /** |
||
81 | * @var Filesize |
||
82 | */ |
||
83 | protected $filesize; |
||
84 | |||
85 | /** |
||
86 | * @var FocalLength |
||
87 | */ |
||
88 | protected $focalLength; |
||
89 | |||
90 | /** |
||
91 | * @var FocusDistance |
||
92 | */ |
||
93 | protected $focusDistance; |
||
94 | |||
95 | /** |
||
96 | * @var Headline |
||
97 | */ |
||
98 | protected $headline; |
||
99 | |||
100 | /** |
||
101 | * @var Height |
||
102 | */ |
||
103 | protected $height; |
||
104 | |||
105 | /** |
||
106 | * @var HorizontalResolution |
||
107 | */ |
||
108 | protected $horizontalResolution; |
||
109 | |||
110 | /** |
||
111 | * @var IsoSpeed |
||
112 | */ |
||
113 | protected $isoSpeed; |
||
114 | |||
115 | /** |
||
116 | * @var Make |
||
117 | */ |
||
118 | protected $make; |
||
119 | |||
120 | /** |
||
121 | * @var Model |
||
122 | */ |
||
123 | protected $model; |
||
124 | |||
125 | /** |
||
126 | * @var MimeType |
||
127 | */ |
||
128 | protected $mimeType; |
||
129 | |||
130 | /** |
||
131 | * @var Software |
||
132 | */ |
||
133 | protected $software; |
||
134 | |||
135 | /** |
||
136 | * @var VerticalResolution |
||
137 | */ |
||
138 | protected $verticalResolution; |
||
139 | |||
140 | /** |
||
141 | * @var Width |
||
142 | */ |
||
143 | protected $width; |
||
144 | |||
145 | /** |
||
146 | * {@inheritDoc} |
||
147 | */ |
||
148 | public function getAperture() |
||
152 | |||
153 | /** |
||
154 | * {@inheritDoc} |
||
155 | */ |
||
156 | public function withAperture(Aperture $aperture) |
||
163 | |||
164 | /** |
||
165 | * {@inheritDoc} |
||
166 | */ |
||
167 | public function getMimeType() |
||
171 | |||
172 | /** |
||
173 | * {@inheritDoc} |
||
174 | */ |
||
175 | public function withMimeType(MimeType $mimeType) |
||
182 | |||
183 | /** |
||
184 | * {@inheritDoc} |
||
185 | */ |
||
186 | public function getFilename() |
||
190 | |||
191 | /** |
||
192 | * {@inheritDoc} |
||
193 | */ |
||
194 | public function withFilename(Filename $filename) |
||
201 | |||
202 | /** |
||
203 | * {@inheritDoc} |
||
204 | */ |
||
205 | public function getFilesize() |
||
209 | |||
210 | /** |
||
211 | * {@inheritDoc} |
||
212 | */ |
||
213 | public function withFilesize(Filesize $filesize) |
||
220 | |||
221 | /** |
||
222 | * {@inheritDoc} |
||
223 | */ |
||
224 | public function getMake() |
||
228 | |||
229 | /** |
||
230 | * {@inheritDoc} |
||
231 | */ |
||
232 | public function withMake(Make $make) |
||
239 | |||
240 | /** |
||
241 | * {@inheritDoc} |
||
242 | */ |
||
243 | public function getModel() |
||
247 | |||
248 | /** |
||
249 | * {@inheritDoc} |
||
250 | */ |
||
251 | public function withModel(Model $model) |
||
258 | |||
259 | /** |
||
260 | * {@inheritDoc} |
||
261 | */ |
||
262 | public function getSoftware() |
||
266 | |||
267 | /** |
||
268 | * {@inheritDoc} |
||
269 | */ |
||
270 | public function withSoftware(Software $software) |
||
277 | |||
278 | /** |
||
279 | * {@inheritDoc} |
||
280 | */ |
||
281 | public function getHeadline() |
||
285 | |||
286 | /** |
||
287 | * {@inheritDoc} |
||
288 | */ |
||
289 | public function withHeadline(Headline $headline) |
||
296 | |||
297 | /** |
||
298 | * {@inheritDoc} |
||
299 | */ |
||
300 | public function getCredit() |
||
304 | |||
305 | /** |
||
306 | * {@inheritDoc} |
||
307 | */ |
||
308 | public function withCredit(Credit $credit) |
||
315 | |||
316 | /** |
||
317 | * {@inheritDoc} |
||
318 | */ |
||
319 | public function getCopyright() |
||
323 | |||
324 | /** |
||
325 | * {@inheritDoc} |
||
326 | */ |
||
327 | public function withCopyright(Copyright $copyright) |
||
334 | |||
335 | /** |
||
336 | * {@inheritDoc} |
||
337 | */ |
||
338 | public function getCaption() |
||
342 | |||
343 | /** |
||
344 | * {@inheritDoc} |
||
345 | */ |
||
346 | public function withCaption(Caption $caption) |
||
353 | |||
354 | /** |
||
355 | * {@inheritDoc} |
||
356 | */ |
||
357 | public function getAuthor() |
||
361 | |||
362 | /** |
||
363 | * {@inheritDoc} |
||
364 | */ |
||
365 | public function withAuthor(Author $author) |
||
372 | |||
373 | /** |
||
374 | * {@inheritDoc} |
||
375 | */ |
||
376 | public function getWidth() |
||
380 | |||
381 | /** |
||
382 | * {@inheritDoc} |
||
383 | */ |
||
384 | public function withWidth(Width $width) |
||
391 | |||
392 | /** |
||
393 | * {@inheritDoc} |
||
394 | */ |
||
395 | public function getHeight() |
||
399 | |||
400 | /** |
||
401 | * {@inheritDoc} |
||
402 | */ |
||
403 | public function withHeight(Height $height) |
||
410 | |||
411 | /** |
||
412 | * {@inheritDoc} |
||
413 | */ |
||
414 | public function getFocalLength() |
||
418 | |||
419 | /** |
||
420 | * {@inheritDoc} |
||
421 | */ |
||
422 | public function withFocalLength(FocalLength $focalLength) |
||
429 | |||
430 | /** |
||
431 | * {@inheritDoc} |
||
432 | */ |
||
433 | public function getFocusDistance() |
||
437 | |||
438 | /** |
||
439 | * {@inheritDoc} |
||
440 | */ |
||
441 | public function withFocusDistance(FocusDistance $focusDistance) |
||
448 | |||
449 | /** |
||
450 | * {@inheritDoc} |
||
451 | */ |
||
452 | public function getHorizontalResolution() |
||
456 | |||
457 | /** |
||
458 | * {@inheritDoc} |
||
459 | */ |
||
460 | public function withHorizontalResolution(HorizontalResolution $horizontalResolution) |
||
467 | |||
468 | /** |
||
469 | * {@inheritDoc} |
||
470 | */ |
||
471 | public function getVerticalResolution() |
||
475 | |||
476 | /** |
||
477 | * {@inheritDoc} |
||
478 | */ |
||
479 | public function withVerticalResolution(VerticalResolution $verticalResolution) |
||
486 | |||
487 | /** |
||
488 | * {@inheritDoc} |
||
489 | */ |
||
490 | public function getExposureTime() |
||
494 | |||
495 | /** |
||
496 | * {@inheritDoc} |
||
497 | */ |
||
498 | public function withExposureTime(ExposureTime $exposureTime) |
||
505 | |||
506 | /** |
||
507 | * {@inheritDoc} |
||
508 | */ |
||
509 | public function getIsoSpeed() |
||
513 | |||
514 | /** |
||
515 | * {@inheritDoc} |
||
516 | */ |
||
517 | public function withIsoSpeed(IsoSpeed $isoSpeed) |
||
524 | } |
||
525 |