Complex classes like Font 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 Font, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class Font implements ComparableInterface |
||
26 | { |
||
27 | /* Underline types */ |
||
28 | const UNDERLINE_NONE = 'none'; |
||
29 | const UNDERLINE_DASH = 'dash'; |
||
30 | const UNDERLINE_DASHHEAVY = 'dashHeavy'; |
||
31 | const UNDERLINE_DASHLONG = 'dashLong'; |
||
32 | const UNDERLINE_DASHLONGHEAVY = 'dashLongHeavy'; |
||
33 | const UNDERLINE_DOUBLE = 'dbl'; |
||
34 | const UNDERLINE_DOTHASH = 'dotDash'; |
||
35 | const UNDERLINE_DOTHASHHEAVY = 'dotDashHeavy'; |
||
36 | const UNDERLINE_DOTDOTDASH = 'dotDotDash'; |
||
37 | const UNDERLINE_DOTDOTDASHHEAVY = 'dotDotDashHeavy'; |
||
38 | const UNDERLINE_DOTTED = 'dotted'; |
||
39 | const UNDERLINE_DOTTEDHEAVY = 'dottedHeavy'; |
||
40 | const UNDERLINE_HEAVY = 'heavy'; |
||
41 | const UNDERLINE_SINGLE = 'sng'; |
||
42 | const UNDERLINE_WAVY = 'wavy'; |
||
43 | const UNDERLINE_WAVYDOUBLE = 'wavyDbl'; |
||
44 | const UNDERLINE_WAVYHEAVY = 'wavyHeavy'; |
||
45 | const UNDERLINE_WORDS = 'words'; |
||
46 | |||
47 | const FONT_FORMAT_LATIN = 'latin'; |
||
48 | const FONT_FORMAT_EAST_ASIAN = 'ea'; |
||
49 | const FONT_FORMAT_COMPLEX_SCRIPT = 'cs'; |
||
50 | |||
51 | /** |
||
52 | * Name |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | private $name; |
||
57 | |||
58 | /** |
||
59 | * Format |
||
60 | * |
||
61 | * @var string |
||
62 | */ |
||
63 | private $format; |
||
64 | |||
65 | /** |
||
66 | * Font Size |
||
67 | * |
||
68 | * @var float|int |
||
69 | */ |
||
70 | private $size; |
||
71 | |||
72 | /** |
||
73 | * Bold |
||
74 | * |
||
75 | * @var boolean |
||
76 | */ |
||
77 | private $bold; |
||
78 | |||
79 | /** |
||
80 | * Italic |
||
81 | * |
||
82 | * @var boolean |
||
83 | */ |
||
84 | private $italic; |
||
85 | |||
86 | /** |
||
87 | * Superscript |
||
88 | * |
||
89 | * @var boolean |
||
90 | */ |
||
91 | private $superScript; |
||
92 | |||
93 | /** |
||
94 | * Subscript |
||
95 | * |
||
96 | * @var boolean |
||
97 | */ |
||
98 | private $subScript; |
||
99 | |||
100 | /** |
||
101 | * Underline |
||
102 | * |
||
103 | * @var string |
||
104 | */ |
||
105 | private $underline; |
||
106 | |||
107 | /** |
||
108 | * Strikethrough |
||
109 | * |
||
110 | * @var boolean |
||
111 | */ |
||
112 | private $strikethrough; |
||
113 | |||
114 | /** |
||
115 | * Foreground color |
||
116 | * |
||
117 | * @var \PhpOffice\PhpPresentation\Style\Color |
||
118 | */ |
||
119 | private $color; |
||
120 | |||
121 | /** |
||
122 | * Character Spacing |
||
123 | * |
||
124 | * @var int |
||
125 | */ |
||
126 | private $characterSpacing; |
||
127 | |||
128 | /** |
||
129 | * Hash index |
||
130 | * |
||
131 | * @var string |
||
132 | */ |
||
133 | private $hashIndex; |
||
134 | |||
135 | /** |
||
136 | * Create a new \PhpOffice\PhpPresentation\Style\Font |
||
137 | */ |
||
138 | 408 | public function __construct() |
|
153 | |||
154 | /** |
||
155 | * Get Name |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | 102 | public function getName() |
|
163 | |||
164 | /** |
||
165 | * Set Name |
||
166 | * |
||
167 | * @param string $pValue |
||
168 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
169 | */ |
||
170 | 125 | public function setName($pValue = 'Calibri') |
|
179 | |||
180 | |||
181 | /** |
||
182 | * Get Font Format |
||
183 | * |
||
184 | * @return string |
||
185 | */ |
||
186 | 29 | public function getFormat() |
|
190 | |||
191 | /** |
||
192 | * Set Font Format |
||
193 | * |
||
194 | * @param string $pValue |
||
195 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
196 | */ |
||
197 | public function setFormat($pValue = self::FONT_FORMAT_LATIN) |
||
206 | |||
207 | /** |
||
208 | * Get Character Spacing |
||
209 | * |
||
210 | * @return double |
||
211 | */ |
||
212 | 31 | public function getCharacterSpacing() |
|
216 | |||
217 | /** |
||
218 | * Set Character Spacing |
||
219 | * Value in pt |
||
220 | * @param float|int $pValue |
||
221 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
222 | */ |
||
223 | 2 | public function setCharacterSpacing($pValue = 0) |
|
232 | |||
233 | /** |
||
234 | * Get Size |
||
235 | * |
||
236 | * @return double |
||
237 | */ |
||
238 | 154 | public function getSize() |
|
242 | |||
243 | /** |
||
244 | * Set Size |
||
245 | * |
||
246 | * @param float|int $pValue |
||
247 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
248 | */ |
||
249 | 292 | public function setSize($pValue = 10) |
|
258 | |||
259 | /** |
||
260 | * Get Bold |
||
261 | * |
||
262 | * @return boolean |
||
263 | */ |
||
264 | 127 | public function isBold() |
|
268 | |||
269 | /** |
||
270 | * Set Bold |
||
271 | * |
||
272 | * @param boolean $pValue |
||
273 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
274 | */ |
||
275 | 10 | public function setBold($pValue = false) |
|
284 | |||
285 | /** |
||
286 | * Get Italic |
||
287 | * |
||
288 | * @return boolean |
||
289 | */ |
||
290 | 139 | public function isItalic() |
|
294 | |||
295 | /** |
||
296 | * Set Italic |
||
297 | * |
||
298 | * @param boolean $pValue |
||
299 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
300 | */ |
||
301 | 9 | public function setItalic($pValue = false) |
|
310 | |||
311 | /** |
||
312 | * Get SuperScript |
||
313 | * |
||
314 | * @return boolean |
||
315 | */ |
||
316 | 66 | public function isSuperScript() |
|
320 | |||
321 | /** |
||
322 | * Set SuperScript |
||
323 | * |
||
324 | * @param boolean $pValue |
||
325 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
326 | */ |
||
327 | 7 | public function setSuperScript($pValue = false) |
|
342 | |||
343 | /** |
||
344 | * Get SubScript |
||
345 | * |
||
346 | * @return boolean |
||
347 | */ |
||
348 | 66 | public function isSubScript() |
|
352 | |||
353 | /** |
||
354 | * Set SubScript |
||
355 | * |
||
356 | * @param boolean $pValue |
||
357 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
358 | */ |
||
359 | 7 | public function setSubScript($pValue = false) |
|
374 | |||
375 | /** |
||
376 | * Get Underline |
||
377 | * |
||
378 | * @return string |
||
379 | */ |
||
380 | 66 | public function getUnderline() |
|
384 | |||
385 | /** |
||
386 | * Set Underline |
||
387 | * |
||
388 | * @param string $pValue \PhpOffice\PhpPresentation\Style\Font underline type |
||
389 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
390 | */ |
||
391 | 8 | public function setUnderline($pValue = self::UNDERLINE_NONE) |
|
400 | |||
401 | /** |
||
402 | * Get Strikethrough |
||
403 | * |
||
404 | * @return boolean |
||
405 | */ |
||
406 | 66 | public function isStrikethrough() |
|
410 | |||
411 | /** |
||
412 | * Set Strikethrough |
||
413 | * |
||
414 | * @param boolean $pValue |
||
415 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
416 | */ |
||
417 | 5 | public function setStrikethrough($pValue = false) |
|
426 | |||
427 | /** |
||
428 | * Get Color |
||
429 | * |
||
430 | * @return \PhpOffice\PhpPresentation\Style\Color|\PhpOffice\PhpPresentation\Style\SchemeColor |
||
431 | */ |
||
432 | 152 | public function getColor() |
|
436 | |||
437 | /** |
||
438 | * Set Color |
||
439 | * |
||
440 | * @param \PhpOffice\PhpPresentation\Style\Color|\PhpOffice\PhpPresentation\Style\SchemeColor $pValue |
||
441 | * @throws \Exception |
||
442 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
443 | */ |
||
444 | 233 | public function setColor($pValue = null) |
|
453 | |||
454 | /** |
||
455 | * Get hash code |
||
456 | * |
||
457 | * @return string Hash code |
||
458 | */ |
||
459 | 90 | public function getHashCode() |
|
463 | |||
464 | /** |
||
465 | * Get hash index |
||
466 | * |
||
467 | * Note that this index may vary during script execution! Only reliable moment is |
||
468 | * while doing a write of a workbook and when changes are not allowed. |
||
469 | * |
||
470 | * @return string Hash index |
||
471 | */ |
||
472 | 1 | public function getHashIndex() |
|
476 | |||
477 | /** |
||
478 | * Set hash index |
||
479 | * |
||
480 | * Note that this index may vary during script execution! Only reliable moment is |
||
481 | * while doing a write of a workbook and when changes are not allowed. |
||
482 | * |
||
483 | * @param string $value Hash index |
||
484 | */ |
||
485 | 1 | public function setHashIndex($value) |
|
489 | } |
||
490 |