Complex classes like CKEditorRenderer 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 CKEditorRenderer, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 24 | class CKEditorRenderer implements CKEditorRendererInterface |
||
| 25 | { |
||
| 26 | /** |
||
| 27 | * @var JsonBuilder |
||
| 28 | */ |
||
| 29 | private $jsonBuilder; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var RouterInterface |
||
| 33 | */ |
||
| 34 | private $router; |
||
| 35 | 790 | ||
| 36 | /** |
||
| 37 | 790 | * @var Packages |
|
| 38 | 790 | */ |
|
| 39 | private $assetsPackages; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var EngineInterface |
||
| 43 | 100 | */ |
|
| 44 | private $templating; |
||
| 45 | 100 | ||
| 46 | /** |
||
| 47 | * @var RequestStack |
||
| 48 | */ |
||
| 49 | private $requestStack; |
||
| 50 | |||
| 51 | 90 | /** |
|
| 52 | * @param JsonBuilder $jsonBuilder |
||
| 53 | 90 | * @param RouterInterface $router |
|
| 54 | * @param Packages $packages |
||
| 55 | * @param RequestStack $requestStack |
||
| 56 | * @param EngineInterface $templating |
||
| 57 | */ |
||
| 58 | public function __construct(JsonBuilder $jsonBuilder, RouterInterface $router, Packages $packages, RequestStack $requestStack, EngineInterface $templating) |
||
| 66 | 488 | ||
| 67 | /** |
||
| 68 | 610 | * {@inheritdoc} |
|
| 69 | 494 | */ |
|
| 70 | 610 | public function renderBasePath($basePath) |
|
| 74 | |||
| 75 | 610 | /** |
|
| 76 | 610 | * {@inheritdoc} |
|
| 77 | 610 | */ |
|
| 78 | 610 | public function renderJsPath($jsPath) |
|
| 82 | 610 | ||
| 83 | 30 | /** |
|
| 84 | 30 | * {@inheritdoc} |
|
| 85 | */ |
||
| 86 | 30 | public function renderWidget($id, array $config, array $options = []) |
|
| 118 | |||
| 119 | /** |
||
| 120 | * {@inheritdoc} |
||
| 121 | */ |
||
| 122 | 30 | public function renderDestroy($id) |
|
| 132 | |||
| 133 | /** |
||
| 134 | * {@inheritdoc} |
||
| 135 | */ |
||
| 136 | 80 | public function renderPlugin($name, array $plugin) |
|
| 145 | 40 | ||
| 146 | 40 | /** |
|
| 147 | 40 | * {@inheritdoc} |
|
| 148 | 32 | */ |
|
| 149 | 32 | public function renderStylesSet($name, array $stylesSet) |
|
| 159 | 80 | ||
| 160 | 64 | /** |
|
| 161 | * {@inheritdoc} |
||
| 162 | */ |
||
| 163 | public function renderTemplate($name, array $template) |
||
| 189 | 80 | ||
| 190 | /** |
||
| 191 | 80 | * @param array $config |
|
| 192 | 80 | * |
|
| 193 | 80 | * @return array |
|
| 194 | 64 | */ |
|
| 195 | 64 | private function fixConfigLanguage(array $config) |
|
| 207 | |||
| 208 | 610 | /** |
|
| 209 | 610 | * @param array $config |
|
| 210 | 488 | * |
|
| 211 | 488 | * @return array |
|
| 212 | 488 | */ |
|
| 213 | 488 | private function fixConfigContentsCss(array $config) |
|
| 226 | 610 | ||
| 227 | 70 | /** |
|
| 228 | 610 | * @param array $config |
|
| 229 | 140 | * @param array $filebrowsers |
|
| 230 | 140 | * |
|
| 231 | 140 | * @return array |
|
| 232 | 140 | */ |
|
| 233 | 112 | private function fixConfigFilebrowsers(array $config, array $filebrowsers) |
|
| 271 | |||
| 272 | /** |
||
| 273 | * @param JsonBuilder $builder |
||
| 274 | 610 | * @param array $config |
|
| 275 | */ |
||
| 276 | 610 | private function fixConfigEscapedValues(JsonBuilder $builder, array $config) |
|
| 295 | 50 | ||
| 296 | 40 | /** |
|
| 297 | * @param string $json |
||
| 298 | 190 | * |
|
| 299 | * @return string |
||
| 300 | */ |
||
| 301 | private function fixConfigConstants($json) |
||
| 305 | |||
| 306 | 680 | /** |
|
| 307 | * @param string $path |
||
| 308 | * |
||
| 309 | * @return string |
||
| 310 | */ |
||
| 311 | private function fixPath($path) |
||
| 325 | } |
||
| 326 |