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 | /** |
||
| 48 | * Name |
||
| 49 | * |
||
| 50 | * @var string |
||
| 51 | */ |
||
| 52 | private $name; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Font Size |
||
| 56 | * |
||
| 57 | * @var float|int |
||
| 58 | */ |
||
| 59 | private $size; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Bold |
||
| 63 | * |
||
| 64 | * @var boolean |
||
| 65 | */ |
||
| 66 | private $bold; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Italic |
||
| 70 | * |
||
| 71 | * @var boolean |
||
| 72 | */ |
||
| 73 | private $italic; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Superscript |
||
| 77 | * |
||
| 78 | * @var boolean |
||
| 79 | */ |
||
| 80 | private $superScript; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Subscript |
||
| 84 | * |
||
| 85 | * @var boolean |
||
| 86 | */ |
||
| 87 | private $subScript; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Underline |
||
| 91 | * |
||
| 92 | * @var string |
||
| 93 | */ |
||
| 94 | private $underline; |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Strikethrough |
||
| 98 | * |
||
| 99 | * @var boolean |
||
| 100 | */ |
||
| 101 | private $strikethrough; |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Foreground color |
||
| 105 | * |
||
| 106 | * @var \PhpOffice\PhpPresentation\Style\Color |
||
| 107 | */ |
||
| 108 | private $color; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Character Spacing |
||
| 112 | * |
||
| 113 | * @var int |
||
| 114 | */ |
||
| 115 | private $characterSpacing; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Hash index |
||
| 119 | * |
||
| 120 | * @var string |
||
| 121 | */ |
||
| 122 | private $hashIndex; |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Create a new \PhpOffice\PhpPresentation\Style\Font |
||
| 126 | */ |
||
| 127 | 408 | public function __construct() |
|
| 141 | |||
| 142 | /** |
||
| 143 | * Get Name |
||
| 144 | * |
||
| 145 | * @return string |
||
| 146 | */ |
||
| 147 | 102 | public function getName() |
|
| 151 | |||
| 152 | /** |
||
| 153 | * Set Name |
||
| 154 | * |
||
| 155 | * @param string $pValue |
||
| 156 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
| 157 | */ |
||
| 158 | 125 | public function setName($pValue = 'Calibri') |
|
| 167 | |||
| 168 | /** |
||
| 169 | * Get Character Spacing |
||
| 170 | * |
||
| 171 | * @return double |
||
| 172 | */ |
||
| 173 | 31 | public function getCharacterSpacing() |
|
| 177 | |||
| 178 | /** |
||
| 179 | * Set Character Spacing |
||
| 180 | * Value in pt |
||
| 181 | * @param float|int $pValue |
||
| 182 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
| 183 | */ |
||
| 184 | 2 | public function setCharacterSpacing($pValue = 0) |
|
| 193 | |||
| 194 | /** |
||
| 195 | * Get Size |
||
| 196 | * |
||
| 197 | * @return double |
||
| 198 | */ |
||
| 199 | 154 | public function getSize() |
|
| 203 | |||
| 204 | /** |
||
| 205 | * Set Size |
||
| 206 | * |
||
| 207 | * @param float|int $pValue |
||
| 208 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
| 209 | */ |
||
| 210 | 292 | public function setSize($pValue = 10) |
|
| 219 | |||
| 220 | /** |
||
| 221 | * Get Bold |
||
| 222 | * |
||
| 223 | * @return boolean |
||
| 224 | */ |
||
| 225 | 127 | public function isBold() |
|
| 229 | |||
| 230 | /** |
||
| 231 | * Set Bold |
||
| 232 | * |
||
| 233 | * @param boolean $pValue |
||
| 234 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
| 235 | */ |
||
| 236 | 10 | public function setBold($pValue = false) |
|
| 245 | |||
| 246 | /** |
||
| 247 | * Get Italic |
||
| 248 | * |
||
| 249 | * @return boolean |
||
| 250 | */ |
||
| 251 | 139 | public function isItalic() |
|
| 255 | |||
| 256 | /** |
||
| 257 | * Set Italic |
||
| 258 | * |
||
| 259 | * @param boolean $pValue |
||
| 260 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
| 261 | */ |
||
| 262 | 9 | public function setItalic($pValue = false) |
|
| 271 | |||
| 272 | /** |
||
| 273 | * Get SuperScript |
||
| 274 | * |
||
| 275 | * @return boolean |
||
| 276 | */ |
||
| 277 | 66 | public function isSuperScript() |
|
| 281 | |||
| 282 | /** |
||
| 283 | * Set SuperScript |
||
| 284 | * |
||
| 285 | * @param boolean $pValue |
||
| 286 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
| 287 | */ |
||
| 288 | 7 | public function setSuperScript($pValue = false) |
|
| 303 | |||
| 304 | /** |
||
| 305 | * Get SubScript |
||
| 306 | * |
||
| 307 | * @return boolean |
||
| 308 | */ |
||
| 309 | 66 | public function isSubScript() |
|
| 313 | |||
| 314 | /** |
||
| 315 | * Set SubScript |
||
| 316 | * |
||
| 317 | * @param boolean $pValue |
||
| 318 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
| 319 | */ |
||
| 320 | 7 | public function setSubScript($pValue = false) |
|
| 335 | |||
| 336 | /** |
||
| 337 | * Get Underline |
||
| 338 | * |
||
| 339 | * @return string |
||
| 340 | */ |
||
| 341 | 66 | public function getUnderline() |
|
| 345 | |||
| 346 | /** |
||
| 347 | * Set Underline |
||
| 348 | * |
||
| 349 | * @param string $pValue \PhpOffice\PhpPresentation\Style\Font underline type |
||
| 350 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
| 351 | */ |
||
| 352 | 8 | public function setUnderline($pValue = self::UNDERLINE_NONE) |
|
| 361 | |||
| 362 | /** |
||
| 363 | * Get Strikethrough |
||
| 364 | * |
||
| 365 | * @return boolean |
||
| 366 | */ |
||
| 367 | 66 | public function isStrikethrough() |
|
| 371 | |||
| 372 | /** |
||
| 373 | * Set Strikethrough |
||
| 374 | * |
||
| 375 | * @param boolean $pValue |
||
| 376 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
| 377 | */ |
||
| 378 | 5 | public function setStrikethrough($pValue = false) |
|
| 387 | |||
| 388 | /** |
||
| 389 | * Get Color |
||
| 390 | * |
||
| 391 | * @return \PhpOffice\PhpPresentation\Style\Color|\PhpOffice\PhpPresentation\Style\SchemeColor |
||
| 392 | */ |
||
| 393 | 152 | public function getColor() |
|
| 397 | |||
| 398 | /** |
||
| 399 | * Set Color |
||
| 400 | * |
||
| 401 | * @param \PhpOffice\PhpPresentation\Style\Color|\PhpOffice\PhpPresentation\Style\SchemeColor $pValue |
||
| 402 | * @throws \Exception |
||
| 403 | * @return \PhpOffice\PhpPresentation\Style\Font |
||
| 404 | */ |
||
| 405 | 233 | public function setColor($pValue = null) |
|
| 414 | |||
| 415 | /** |
||
| 416 | * Get hash code |
||
| 417 | * |
||
| 418 | * @return string Hash code |
||
| 419 | */ |
||
| 420 | 90 | public function getHashCode() |
|
| 424 | |||
| 425 | /** |
||
| 426 | * Get hash index |
||
| 427 | * |
||
| 428 | * Note that this index may vary during script execution! Only reliable moment is |
||
| 429 | * while doing a write of a workbook and when changes are not allowed. |
||
| 430 | * |
||
| 431 | * @return string Hash index |
||
| 432 | */ |
||
| 433 | 1 | public function getHashIndex() |
|
| 437 | |||
| 438 | /** |
||
| 439 | * Set hash index |
||
| 440 | * |
||
| 441 | * Note that this index may vary during script execution! Only reliable moment is |
||
| 442 | * while doing a write of a workbook and when changes are not allowed. |
||
| 443 | * |
||
| 444 | * @param string $value Hash index |
||
| 445 | */ |
||
| 446 | 1 | public function setHashIndex($value) |
|
| 450 | } |
||
| 451 |