Complex classes like StyleManager 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 StyleManager, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | class StyleManager extends \Box\Spout\Writer\Common\Manager\Style\StyleManager |
||
| 18 | { |
||
| 19 | use ManagesCellSize; |
||
| 20 | |||
| 21 | /** @var StyleRegistry */ |
||
| 22 | protected $styleRegistry; |
||
| 23 | |||
| 24 | /** |
||
| 25 | 36 | * @param StyleRegistry $styleRegistry |
|
| 26 | */ |
||
| 27 | public function __construct(StyleRegistry $styleRegistry, OptionsManagerInterface $optionsManager) |
||
| 34 | 36 | ||
| 35 | 36 | /** |
|
| 36 | * Returns the content of the "styles.xml" file, given a list of styles. |
||
| 37 | * |
||
| 38 | 36 | * @param int $numWorksheets Number of worksheets created |
|
| 39 | * @return string |
||
| 40 | */ |
||
| 41 | 36 | public function getStylesXMLFileContent($numWorksheets) |
|
| 59 | |||
| 60 | /** |
||
| 61 | * Returns the content of the "<office:font-face-decls>" section, inside "styles.xml" file. |
||
| 62 | * |
||
| 63 | * @return string |
||
| 64 | */ |
||
| 65 | 36 | protected function getFontFaceSectionContent() |
|
| 75 | |||
| 76 | 36 | /** |
|
| 77 | 36 | * Returns the content of the "<office:styles>" section, inside "styles.xml" file. |
|
| 78 | 36 | * |
|
| 79 | * @return string |
||
| 80 | */ |
||
| 81 | protected function getStylesSectionContent() |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Returns the content of the "<office:automatic-styles>" section, inside "styles.xml" file. |
||
| 102 | * |
||
| 103 | * @param int $numWorksheets Number of worksheets created |
||
| 104 | 36 | * @return string |
|
| 105 | */ |
||
| 106 | 36 | protected function getAutomaticStylesSectionContent($numWorksheets) |
|
| 124 | |||
| 125 | /** |
||
| 126 | * Returns the content of the "<office:master-styles>" section, inside "styles.xml" file. |
||
| 127 | * |
||
| 128 | * @param int $numWorksheets Number of worksheets created |
||
| 129 | * @return string |
||
| 130 | 36 | */ |
|
| 131 | protected function getMasterStylesSectionContent($numWorksheets) |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Returns the contents of the "<office:font-face-decls>" section, inside "content.xml" file. |
||
| 153 | * |
||
| 154 | * @return string |
||
| 155 | */ |
||
| 156 | public function getContentXmlFontFaceSectionContent() |
||
| 166 | 36 | ||
| 167 | /** |
||
| 168 | * Returns the contents of the "<office:automatic-styles>" section, inside "content.xml" file. |
||
| 169 | * |
||
| 170 | * @param Worksheet[] $worksheets |
||
| 171 | * @return string |
||
| 172 | */ |
||
| 173 | public function getContentXmlAutomaticStylesSectionContent($worksheets) |
||
| 219 | 36 | ||
| 220 | 35 | /** |
|
| 221 | * Returns the contents of the "<style:style>" section, inside "<office:automatic-styles>" section |
||
| 222 | * |
||
| 223 | * @param \Box\Spout\Common\Entity\Style\Style $style |
||
| 224 | 5 | * @return string |
|
| 225 | 5 | */ |
|
| 226 | protected function getStyleSectionContent($style) |
||
| 240 | 5 | ||
| 241 | 5 | /** |
|
| 242 | 1 | * Returns the contents of the "<style:text-properties>" section, inside "<style:style>" section |
|
| 243 | * |
||
| 244 | * @param \Box\Spout\Common\Entity\Style\Style $style |
||
| 245 | 5 | * @return string |
|
| 246 | 5 | */ |
|
| 247 | 1 | private function getTextPropertiesSectionContent($style) |
|
| 257 | |||
| 258 | 5 | /** |
|
| 259 | 1 | * Returns the contents of the fonts definition section, inside "<style:text-properties>" section |
|
| 260 | * |
||
| 261 | 5 | * @param \Box\Spout\Common\Entity\Style\Style $style |
|
| 262 | 2 | * |
|
| 263 | * @return string |
||
| 264 | 5 | */ |
|
| 265 | 1 | private function getFontSectionContent($style) |
|
| 300 | 1 | ||
| 301 | /** |
||
| 302 | * Returns the contents of the "<style:paragraph-properties>" section, inside "<style:style>" section |
||
| 303 | * |
||
| 304 | * @param \Box\Spout\Common\Entity\Style\Style $style |
||
| 305 | * |
||
| 306 | * @return string |
||
| 307 | */ |
||
| 308 | private function getParagraphPropertiesSectionContent($style) |
||
| 309 | { |
||
| 310 | if (!$style->shouldApplyCellAlignment()) { |
||
| 311 | return ''; |
||
| 312 | } |
||
| 313 | 1 | ||
| 314 | return '<style:paragraph-properties ' |
||
| 315 | 1 | . $this->getCellAlignmentSectionContent($style) |
|
| 316 | . '/>'; |
||
| 317 | 1 | } |
|
| 318 | |||
| 319 | /** |
||
| 320 | * Returns the contents of the cell alignment definition for the "<style:paragraph-properties>" section |
||
| 321 | * |
||
| 322 | * @param \Box\Spout\Common\Entity\Style\Style $style |
||
| 323 | * |
||
| 324 | * @return string |
||
| 325 | */ |
||
| 326 | private function getCellAlignmentSectionContent($style) |
||
| 333 | 3 | ||
| 334 | /** |
||
| 335 | * Even though "left" and "right" alignments are part of the spec, and interpreted |
||
| 336 | 36 | * respectively as "start" and "end", using the recommended values increase compatibility |
|
| 337 | 1 | * with software that will read the created ODS file. |
|
| 338 | * |
||
| 339 | * @param string $cellAlignment |
||
| 340 | 36 | * |
|
| 341 | 2 | * @return string |
|
| 342 | */ |
||
| 343 | private function transformCellAlignment($cellAlignment) |
||
| 354 | 3 | ||
| 355 | /** |
||
| 356 | 3 | * Returns the contents of the "<style:table-cell-properties>" section, inside "<style:style>" section |
|
| 357 | * |
||
| 358 | * @param \Box\Spout\Common\Entity\Style\Style $style |
||
| 359 | * @return string |
||
| 360 | */ |
||
| 361 | private function getTableCellPropertiesSectionContent($style) |
||
| 381 | |||
| 382 | 2 | /** |
|
| 383 | * Returns the contents of the wrap text definition for the "<style:table-cell-properties>" section |
||
| 384 | * |
||
| 385 | * @return string |
||
| 386 | */ |
||
| 387 | private function getWrapTextXMLContent() |
||
| 391 | |||
| 392 | /** |
||
| 393 | * Returns the contents of the borders definition for the "<style:table-cell-properties>" section |
||
| 394 | * |
||
| 395 | * @param \Box\Spout\Common\Entity\Style\Style $style |
||
| 396 | * @return string |
||
| 397 | */ |
||
| 398 | private function getBorderXMLContent($style) |
||
| 406 | |||
| 407 | /** |
||
| 408 | * Returns the contents of the background color definition for the "<style:table-cell-properties>" section |
||
| 409 | * |
||
| 410 | * @param \Box\Spout\Common\Entity\Style\Style $style |
||
| 411 | * @return string |
||
| 412 | */ |
||
| 413 | private function getBackgroundColorXMLContent($style) |
||
| 417 | |||
| 418 | public function getTableColumnStylesXMLContent() : string |
||
| 435 | |||
| 436 | public function getStyledTableColumnXMLContent(int $maxNumColumns) : string |
||
| 455 | } |
||
| 456 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..