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