Complex classes like PHPExcel_Writer_Excel5_Xf 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 PHPExcel_Writer_Excel5_Xf, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 71 | class PHPExcel_Writer_Excel5_Xf |
||
| 72 | { |
||
| 73 | /** |
||
| 74 | * Style XF or a cell XF ? |
||
| 75 | * |
||
| 76 | * @var boolean |
||
| 77 | */ |
||
| 78 | private $_isStyleXf; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * Index to the FONT record. Index 4 does not exist |
||
| 82 | * @var integer |
||
| 83 | */ |
||
| 84 | private $_fontIndex; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * An index (2 bytes) to a FORMAT record (number format). |
||
| 88 | * @var integer |
||
| 89 | */ |
||
| 90 | public $_numberFormatIndex; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * 1 bit, apparently not used. |
||
| 94 | * @var integer |
||
| 95 | */ |
||
| 96 | public $_text_justlast; |
||
| 97 | |||
| 98 | /** |
||
| 99 | * The cell's foreground color. |
||
| 100 | * @var integer |
||
| 101 | */ |
||
| 102 | public $_fg_color; |
||
| 103 | |||
| 104 | /** |
||
| 105 | * The cell's background color. |
||
| 106 | * @var integer |
||
| 107 | */ |
||
| 108 | public $_bg_color; |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Color of the bottom border of the cell. |
||
| 112 | * @var integer |
||
| 113 | */ |
||
| 114 | public $_bottom_color; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Color of the top border of the cell. |
||
| 118 | * @var integer |
||
| 119 | */ |
||
| 120 | public $_top_color; |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Color of the left border of the cell. |
||
| 124 | * @var integer |
||
| 125 | */ |
||
| 126 | public $_left_color; |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Color of the right border of the cell. |
||
| 130 | * @var integer |
||
| 131 | */ |
||
| 132 | public $_right_color; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Constructor |
||
| 136 | * |
||
| 137 | * @access public |
||
| 138 | * @param PHPExcel_Style The XF format |
||
| 139 | */ |
||
| 140 | public function __construct(PHPExcel_Style $style = null) |
||
| 162 | |||
| 163 | |||
| 164 | /** |
||
| 165 | * Generate an Excel BIFF XF record (style or cell). |
||
| 166 | * |
||
| 167 | * @return string The XF record |
||
| 168 | */ |
||
| 169 | function writeXf() |
||
| 268 | |||
| 269 | /** |
||
| 270 | * Is this a style XF ? |
||
| 271 | * |
||
| 272 | * @param boolean $value |
||
| 273 | */ |
||
| 274 | public function setIsStyleXf($value) |
||
| 278 | |||
| 279 | /** |
||
| 280 | * Sets the cell's bottom border color |
||
| 281 | * |
||
| 282 | * @access public |
||
| 283 | * @param int $colorIndex Color index |
||
| 284 | */ |
||
| 285 | function setBottomColor($colorIndex) |
||
| 289 | |||
| 290 | /** |
||
| 291 | * Sets the cell's top border color |
||
| 292 | * |
||
| 293 | * @access public |
||
| 294 | * @param int $colorIndex Color index |
||
| 295 | */ |
||
| 296 | function setTopColor($colorIndex) |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Sets the cell's left border color |
||
| 303 | * |
||
| 304 | * @access public |
||
| 305 | * @param int $colorIndex Color index |
||
| 306 | */ |
||
| 307 | function setLeftColor($colorIndex) |
||
| 311 | |||
| 312 | /** |
||
| 313 | * Sets the cell's right border color |
||
| 314 | * |
||
| 315 | * @access public |
||
| 316 | * @param int $colorIndex Color index |
||
| 317 | */ |
||
| 318 | function setRightColor($colorIndex) |
||
| 322 | |||
| 323 | /** |
||
| 324 | * Sets the cell's diagonal border color |
||
| 325 | * |
||
| 326 | * @access public |
||
| 327 | * @param int $colorIndex Color index |
||
| 328 | */ |
||
| 329 | function setDiagColor($colorIndex) |
||
| 333 | |||
| 334 | |||
| 335 | /** |
||
| 336 | * Sets the cell's foreground color |
||
| 337 | * |
||
| 338 | * @access public |
||
| 339 | * @param int $colorIndex Color index |
||
| 340 | */ |
||
| 341 | function setFgColor($colorIndex) |
||
| 345 | |||
| 346 | /** |
||
| 347 | * Sets the cell's background color |
||
| 348 | * |
||
| 349 | * @access public |
||
| 350 | * @param int $colorIndex Color index |
||
| 351 | */ |
||
| 352 | function setBgColor($colorIndex) |
||
| 356 | |||
| 357 | /** |
||
| 358 | * Sets the index to the number format record |
||
| 359 | * It can be date, time, currency, etc... |
||
| 360 | * |
||
| 361 | * @access public |
||
| 362 | * @param integer $numberFormatIndex Index to format record |
||
| 363 | */ |
||
| 364 | function setNumberFormatIndex($numberFormatIndex) |
||
| 368 | |||
| 369 | /** |
||
| 370 | * Set the font index. |
||
| 371 | * |
||
| 372 | * @param int $value Font index, note that value 4 does not exist |
||
| 373 | */ |
||
| 374 | public function setFontIndex($value) |
||
| 378 | |||
| 379 | /** |
||
| 380 | * Map of BIFF2-BIFF8 codes for border styles |
||
| 381 | * @static array of int |
||
| 382 | * |
||
| 383 | */ |
||
| 384 | private static $_mapBorderStyle = array ( PHPExcel_Style_Border::BORDER_NONE => 0x00, |
||
| 385 | PHPExcel_Style_Border::BORDER_THIN => 0x01, |
||
| 386 | PHPExcel_Style_Border::BORDER_MEDIUM => 0x02, |
||
| 387 | PHPExcel_Style_Border::BORDER_DASHED => 0x03, |
||
| 388 | PHPExcel_Style_Border::BORDER_DOTTED => 0x04, |
||
| 389 | PHPExcel_Style_Border::BORDER_THICK => 0x05, |
||
| 390 | PHPExcel_Style_Border::BORDER_DOUBLE => 0x06, |
||
| 391 | PHPExcel_Style_Border::BORDER_HAIR => 0x07, |
||
| 392 | PHPExcel_Style_Border::BORDER_MEDIUMDASHED => 0x08, |
||
| 393 | PHPExcel_Style_Border::BORDER_DASHDOT => 0x09, |
||
| 394 | PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT => 0x0A, |
||
| 395 | PHPExcel_Style_Border::BORDER_DASHDOTDOT => 0x0B, |
||
| 396 | PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT => 0x0C, |
||
| 397 | PHPExcel_Style_Border::BORDER_SLANTDASHDOT => 0x0D, |
||
| 398 | ); |
||
| 399 | |||
| 400 | /** |
||
| 401 | * Map border style |
||
| 402 | * |
||
| 403 | * @param string $borderStyle |
||
| 404 | * @return int |
||
| 405 | */ |
||
| 406 | private static function _mapBorderStyle($borderStyle) { |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Map of BIFF2-BIFF8 codes for fill types |
||
| 414 | * @static array of int |
||
| 415 | * |
||
| 416 | */ |
||
| 417 | private static $_mapFillType = array( PHPExcel_Style_Fill::FILL_NONE => 0x00, |
||
| 418 | PHPExcel_Style_Fill::FILL_SOLID => 0x01, |
||
| 419 | PHPExcel_Style_Fill::FILL_PATTERN_MEDIUMGRAY => 0x02, |
||
| 420 | PHPExcel_Style_Fill::FILL_PATTERN_DARKGRAY => 0x03, |
||
| 421 | PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRAY => 0x04, |
||
| 422 | PHPExcel_Style_Fill::FILL_PATTERN_DARKHORIZONTAL => 0x05, |
||
| 423 | PHPExcel_Style_Fill::FILL_PATTERN_DARKVERTICAL => 0x06, |
||
| 424 | PHPExcel_Style_Fill::FILL_PATTERN_DARKDOWN => 0x07, |
||
| 425 | PHPExcel_Style_Fill::FILL_PATTERN_DARKUP => 0x08, |
||
| 426 | PHPExcel_Style_Fill::FILL_PATTERN_DARKGRID => 0x09, |
||
| 427 | PHPExcel_Style_Fill::FILL_PATTERN_DARKTRELLIS => 0x0A, |
||
| 428 | PHPExcel_Style_Fill::FILL_PATTERN_LIGHTHORIZONTAL => 0x0B, |
||
| 429 | PHPExcel_Style_Fill::FILL_PATTERN_LIGHTVERTICAL => 0x0C, |
||
| 430 | PHPExcel_Style_Fill::FILL_PATTERN_LIGHTDOWN => 0x0D, |
||
| 431 | PHPExcel_Style_Fill::FILL_PATTERN_LIGHTUP => 0x0E, |
||
| 432 | PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRID => 0x0F, |
||
| 433 | PHPExcel_Style_Fill::FILL_PATTERN_LIGHTTRELLIS => 0x10, |
||
| 434 | PHPExcel_Style_Fill::FILL_PATTERN_GRAY125 => 0x11, |
||
| 435 | PHPExcel_Style_Fill::FILL_PATTERN_GRAY0625 => 0x12, |
||
| 436 | PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR => 0x00, // does not exist in BIFF8 |
||
| 437 | PHPExcel_Style_Fill::FILL_GRADIENT_PATH => 0x00, // does not exist in BIFF8 |
||
| 438 | ); |
||
| 439 | /** |
||
| 440 | * Map fill type |
||
| 441 | * |
||
| 442 | * @param string $fillType |
||
| 443 | * @return int |
||
| 444 | */ |
||
| 445 | private static function _mapFillType($fillType) { |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Map of BIFF2-BIFF8 codes for horizontal alignment |
||
| 453 | * @static array of int |
||
| 454 | * |
||
| 455 | */ |
||
| 456 | private static $_mapHAlign = array( PHPExcel_Style_Alignment::HORIZONTAL_GENERAL => 0, |
||
| 457 | PHPExcel_Style_Alignment::HORIZONTAL_LEFT => 1, |
||
| 458 | PHPExcel_Style_Alignment::HORIZONTAL_CENTER => 2, |
||
| 459 | PHPExcel_Style_Alignment::HORIZONTAL_RIGHT => 3, |
||
| 460 | PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY => 5, |
||
| 461 | PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS => 6, |
||
| 462 | ); |
||
| 463 | /** |
||
| 464 | * Map to BIFF2-BIFF8 codes for horizontal alignment |
||
| 465 | * |
||
| 466 | * @param string $hAlign |
||
| 467 | * @return int |
||
| 468 | */ |
||
| 469 | private function _mapHAlign($hAlign) |
||
| 475 | |||
| 476 | /** |
||
| 477 | * Map of BIFF2-BIFF8 codes for vertical alignment |
||
| 478 | * @static array of int |
||
| 479 | * |
||
| 480 | */ |
||
| 481 | private static $_mapVAlign = array( PHPExcel_Style_Alignment::VERTICAL_TOP => 0, |
||
| 482 | PHPExcel_Style_Alignment::VERTICAL_CENTER => 1, |
||
| 483 | PHPExcel_Style_Alignment::VERTICAL_BOTTOM => 2, |
||
| 484 | PHPExcel_Style_Alignment::VERTICAL_JUSTIFY => 3, |
||
| 485 | ); |
||
| 486 | /** |
||
| 487 | * Map to BIFF2-BIFF8 codes for vertical alignment |
||
| 488 | * |
||
| 489 | * @param string $vAlign |
||
| 490 | * @return int |
||
| 491 | */ |
||
| 492 | private static function _mapVAlign($vAlign) { |
||
| 497 | |||
| 498 | /** |
||
| 499 | * Map to BIFF8 codes for text rotation angle |
||
| 500 | * |
||
| 501 | * @param int $textRotation |
||
| 502 | * @return int |
||
| 503 | */ |
||
| 504 | private static function _mapTextRotation($textRotation) { |
||
| 515 | |||
| 516 | /** |
||
| 517 | * Map locked |
||
| 518 | * |
||
| 519 | * @param string |
||
| 520 | * @return int |
||
| 521 | */ |
||
| 522 | private static function _mapLocked($locked) { |
||
| 530 | |||
| 531 | /** |
||
| 532 | * Map hidden |
||
| 533 | * |
||
| 534 | * @param string |
||
| 535 | * @return int |
||
| 536 | */ |
||
| 537 | private static function _mapHidden($hidden) { |
||
| 545 | |||
| 546 | } |
||
| 547 |
According to the PSR-2, the body of a default statement must start on the line immediately following the statement.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.