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 |
||
| 25 | class CKEditorRenderer implements CKEditorRendererInterface |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * @var ContainerInterface |
||
| 29 | */ |
||
| 30 | private $container; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param ContainerInterface $container |
||
| 34 | */ |
||
| 35 | 711 | public function __construct(ContainerInterface $container) |
|
| 36 | { |
||
| 37 | 711 | $this->container = $container; |
|
| 38 | 711 | } |
|
| 39 | |||
| 40 | /** |
||
| 41 | * {@inheritdoc} |
||
| 42 | */ |
||
| 43 | 90 | public function renderBasePath($basePath) |
|
| 47 | |||
| 48 | /** |
||
| 49 | * {@inheritdoc} |
||
| 50 | */ |
||
| 51 | 81 | public function renderJsPath($jsPath) |
|
| 55 | |||
| 56 | /** |
||
| 57 | * {@inheritdoc} |
||
| 58 | */ |
||
| 59 | 549 | public function renderWidget($id, array $config, array $options = []) |
|
| 91 | |||
| 92 | /** |
||
| 93 | * {@inheritdoc} |
||
| 94 | */ |
||
| 95 | 99 | public function renderDestroy($id) |
|
| 96 | { |
||
| 97 | 99 | return sprintf( |
|
| 98 | 'if (CKEDITOR.instances["%1$s"]) { '. |
||
| 99 | 77 | 'CKEDITOR.instances["%1$s"].destroy(true); '. |
|
| 100 | 77 | 'delete CKEDITOR.instances["%1$s"]; '. |
|
| 101 | 99 | '}', |
|
| 102 | 22 | $id |
|
| 103 | 77 | ); |
|
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * {@inheritdoc} |
||
| 108 | */ |
||
| 109 | 36 | public function renderPlugin($name, array $plugin) |
|
| 118 | |||
| 119 | /** |
||
| 120 | * {@inheritdoc} |
||
| 121 | */ |
||
| 122 | 27 | public function renderStylesSet($name, array $stylesSet) |
|
| 132 | |||
| 133 | /** |
||
| 134 | * {@inheritdoc} |
||
| 135 | */ |
||
| 136 | 72 | public function renderTemplate($name, array $template) |
|
| 162 | |||
| 163 | /** |
||
| 164 | * @param array $config |
||
| 165 | * |
||
| 166 | * @return array |
||
| 167 | */ |
||
| 168 | 549 | private function fixConfigLanguage(array $config) |
|
| 180 | |||
| 181 | /** |
||
| 182 | * @param array $config |
||
| 183 | * |
||
| 184 | * @return array |
||
| 185 | */ |
||
| 186 | 549 | private function fixConfigContentsCss(array $config) |
|
| 199 | |||
| 200 | /** |
||
| 201 | * @param array $config |
||
| 202 | * @param array $filebrowsers |
||
| 203 | * |
||
| 204 | * @return array |
||
| 205 | */ |
||
| 206 | 549 | private function fixConfigFilebrowsers(array $config, array $filebrowsers) |
|
| 244 | |||
| 245 | /** |
||
| 246 | * @param JsonBuilder $builder |
||
| 247 | * @param array $config |
||
| 248 | */ |
||
| 249 | 549 | private function fixConfigEscapedValues(JsonBuilder $builder, array $config) |
|
| 268 | |||
| 269 | /** |
||
| 270 | * @param string $json |
||
| 271 | * |
||
| 272 | * @return string |
||
| 273 | */ |
||
| 274 | 549 | private function fixConfigConstants($json) |
|
| 278 | |||
| 279 | /** |
||
| 280 | * @param string $path |
||
| 281 | * |
||
| 282 | * @return string |
||
| 283 | */ |
||
| 284 | 243 | private function fixPath($path) |
|
| 300 | |||
| 301 | /** |
||
| 302 | * @return JsonBuilder |
||
| 303 | */ |
||
| 304 | 612 | private function getJsonBuilder() |
|
| 308 | |||
| 309 | /** |
||
| 310 | * @return string|null |
||
| 311 | */ |
||
| 312 | 531 | private function getLanguage() |
|
| 322 | |||
| 323 | /** |
||
| 324 | * @return Request|null |
||
| 325 | */ |
||
| 326 | 531 | private function getRequest() |
|
| 330 | |||
| 331 | /** |
||
| 332 | * @return \Twig_Environment|EngineInterface |
||
| 333 | */ |
||
| 334 | 36 | private function getTemplating() |
|
| 340 | |||
| 341 | /** |
||
| 342 | * @return Packages|null |
||
| 343 | */ |
||
| 344 | 243 | private function getAssets() |
|
| 348 | |||
| 349 | /** |
||
| 350 | * @return RouterInterface |
||
| 351 | */ |
||
| 352 | 189 | private function getRouter() |
|
| 356 | } |
||
| 357 |