Complex classes like AbstractComponentTwigExtension 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 AbstractComponentTwigExtension, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 30 | abstract class AbstractComponentTwigExtension extends AbstractBootstrapTwigExtension { |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Translator. |
||
| 34 | * |
||
| 35 | * @var TranslatorInterface |
||
| 36 | */ |
||
| 37 | private $translator; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Constructor. |
||
| 41 | * |
||
| 42 | * @param TranslatorInterface $translator The translator. |
||
| 43 | */ |
||
| 44 | protected function __construct(TranslatorInterface $translator = null) { |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Displays a Bootstrap alert. |
||
| 51 | * |
||
| 52 | * @param string $content The alert content. |
||
| 53 | * @param boolean $dismissible Dismissible alert ? |
||
| 54 | * @param string $class The alert class. |
||
| 55 | * @return string Returns the Bootstrap alert. |
||
| 56 | */ |
||
| 57 | protected function bootstrapAlert($content, $dismissible, $class) { |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Displays a Bootstrap badge. |
||
| 79 | * |
||
| 80 | * @param string $content The badge content. |
||
| 81 | * @return string Returns the Bootstrap badge. |
||
| 82 | */ |
||
| 83 | protected function bootstrapBadge($content) { |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Displays a Bootstrap breadcrumb. |
||
| 102 | * |
||
| 103 | * @param NavigationNode $node The navigation node. |
||
| 104 | * @param boolean $last Last node ?. |
||
| 105 | * @return string Returns the Bootstrap breadcrumb. |
||
| 106 | */ |
||
| 107 | private function bootstrapBreadcrumb(NavigationNode $node, $last) { |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Displays a Bootstrap breadcrumbs. |
||
| 124 | * |
||
| 125 | * @param NavigationTree $tree The tree. |
||
| 126 | * @return string Returns the Bootstrap breadcrumbs. |
||
| 127 | */ |
||
| 128 | protected function bootstrapBreadcrumbs(NavigationTree $tree) { |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Displays a Bootstrap button. |
||
| 156 | * |
||
| 157 | * @param string $content The button content. |
||
| 158 | * @param string $title The button title. |
||
| 159 | * @param string $size The button size. |
||
| 160 | * @param boolean $block Block button ? |
||
| 161 | * @param booelan $active Active button ? |
||
| 162 | * @param booelan $disable Disable button ? |
||
| 163 | * @param string $class The button class. |
||
| 164 | * @param string $icon The button icon. |
||
| 165 | * @return string Returns the Bootstrap button. |
||
| 166 | */ |
||
| 167 | protected function bootstrapButton($content, $title, $size, $block, $active, $disable, $class, $icon) { |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Displays a Bootstrap button group. |
||
| 195 | * |
||
| 196 | * @param string $class The class. |
||
| 197 | * @param string $role The role. |
||
| 198 | * @param array $buttons The buttons. |
||
| 199 | * @return string Returns the Bootstrap button group. |
||
| 200 | */ |
||
| 201 | protected function bootstrapButtonGroup($class, $role, array $buttons) { |
||
| 218 | |||
| 219 | /** |
||
| 220 | * Displays a Bootstrap dropdown "Button". |
||
| 221 | * |
||
| 222 | * @param string $content The content. |
||
| 223 | * @param string $id The id. |
||
| 224 | * @param boolean $expanded Expanded ? |
||
| 225 | * @param string $class The class. |
||
| 226 | * @return string Returns the Bootstrap dropdown "Button". |
||
| 227 | */ |
||
| 228 | protected function bootstrapDropdownButton($content, $id, $expanded, $class) { |
||
| 254 | |||
| 255 | /** |
||
| 256 | * Displays a Bootstrap dropdown "Divider". |
||
| 257 | * |
||
| 258 | * @return string Returns the Bootstrap dropdown "Divider". |
||
| 259 | */ |
||
| 260 | protected function bootstrapDropdownDivider() { |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Displays a Bootstrap dropdown "Header". |
||
| 277 | * |
||
| 278 | * @param string $content The content. |
||
| 279 | * @return string Returns the Bootstrap dropdown "Header". |
||
| 280 | */ |
||
| 281 | protected function bootstrapDropdownHeader($content) { |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Displays a Bootstrap glyphicon. |
||
| 300 | * |
||
| 301 | * @param string $name The glyphicon name. |
||
| 302 | * @return string Returns the Bootstrap glyphicon. |
||
| 303 | */ |
||
| 304 | protected function bootstrapGlyphicon($name, $style) { |
||
| 320 | |||
| 321 | /** |
||
| 322 | * Displays a Bootstrap label. |
||
| 323 | * |
||
| 324 | * @param string $content The label content. |
||
| 325 | * @param string $class The label class. |
||
| 326 | * @return string Returns the Bootstrap label. |
||
| 327 | */ |
||
| 328 | protected function bootstrapLabel($content, $class) { |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Displays a Bootstrap progress bar. |
||
| 347 | * |
||
| 348 | * @param string $content The progress bar content. |
||
| 349 | * @param integer $value The progress bar value. |
||
| 350 | * @param integer $min The progress bar min. |
||
| 351 | * @param integer $max The progress bar max. |
||
| 352 | * @param boolean $striped Progress bar striped ? |
||
| 353 | * @param boolean $animated Progress bar animated ? |
||
| 354 | * @param string $class The progress bar class. |
||
| 355 | * @return string Returns the Bootstrap progress bar. |
||
| 356 | */ |
||
| 357 | protected function bootstrapProgressBar($content, $value, $min, $max, $striped, $animated, $class = null) { |
||
| 381 | |||
| 382 | /** |
||
| 383 | * Get the translator. |
||
| 384 | * |
||
| 385 | * @return TranslatorInterface Returns the translator. |
||
| 386 | */ |
||
| 387 | public function getTranslator() { |
||
| 390 | |||
| 391 | /** |
||
| 392 | * Set the translator. |
||
| 393 | * @param TranslatorInterface $translator The translator. |
||
| 394 | * @return AbstractComponentTwigExtension Returns this component Twig extension. |
||
| 395 | */ |
||
| 396 | protected function setTranslator(TranslatorInterface $translator = null) { |
||
| 400 | |||
| 401 | } |
||
| 402 |