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 |
||
26 | class CKEditorRenderer implements CKEditorRendererInterface |
||
27 | { |
||
28 | /** |
||
29 | * @var JsonBuilder |
||
30 | */ |
||
31 | private $jsonBuilder; |
||
32 | /** |
||
33 | * @var RouterInterface |
||
34 | */ |
||
35 | 790 | private $router; |
|
36 | /** |
||
37 | 790 | * @var Packages |
|
38 | 790 | */ |
|
39 | private $assetsPagages; |
||
40 | /** |
||
41 | * @var ContainerInterface |
||
42 | */ |
||
43 | 100 | private $container; |
|
44 | /** |
||
45 | 100 | * @var Request |
|
46 | */ |
||
47 | private $request; |
||
48 | |||
49 | /** |
||
50 | * @param JsonBuilder $jsonBuilder |
||
51 | 90 | * @param RouterInterface $router |
|
52 | * @param Packages $packages |
||
53 | 90 | * @param RequestStack $requestStack |
|
54 | * @param ContainerInterface $container |
||
55 | */ |
||
56 | public function __construct(JsonBuilder $jsonBuilder, RouterInterface $router, Packages $packages, RequestStack $requestStack, ContainerInterface $container) |
||
64 | 610 | ||
65 | 610 | /** |
|
66 | 488 | * {@inheritdoc} |
|
67 | */ |
||
68 | 610 | public function renderBasePath($basePath) |
|
72 | 610 | ||
73 | 610 | /** |
|
74 | * {@inheritdoc} |
||
75 | 610 | */ |
|
76 | 610 | public function renderJsPath($jsPath) |
|
80 | 488 | ||
81 | /** |
||
82 | 610 | * {@inheritdoc} |
|
83 | 30 | */ |
|
84 | 30 | public function renderWidget($id, array $config, array $options = []) |
|
116 | 32 | ||
117 | /** |
||
118 | * {@inheritdoc} |
||
119 | */ |
||
120 | public function renderDestroy($id) |
||
130 | 24 | ||
131 | /** |
||
132 | * {@inheritdoc} |
||
133 | */ |
||
134 | public function renderPlugin($name, array $plugin) |
||
143 | 80 | ||
144 | 80 | /** |
|
145 | 40 | * {@inheritdoc} |
|
146 | 40 | */ |
|
147 | 40 | public function renderStylesSet($name, array $stylesSet) |
|
157 | 80 | ||
158 | 80 | /** |
|
159 | 80 | * {@inheritdoc} |
|
160 | 64 | */ |
|
161 | public function renderTemplate($name, array $template) |
||
187 | |||
188 | 610 | /** |
|
189 | 80 | * @param array $config |
|
190 | * |
||
191 | 80 | * @return array |
|
192 | 80 | */ |
|
193 | 80 | private function fixConfigLanguage(array $config) |
|
205 | |||
206 | 610 | /** |
|
207 | * @param array $config |
||
208 | 610 | * |
|
209 | 610 | * @return array |
|
210 | 488 | */ |
|
211 | 488 | private function fixConfigContentsCss(array $config) |
|
224 | 610 | ||
225 | /** |
||
226 | 610 | * @param array $config |
|
227 | 70 | * @param array $filebrowsers |
|
228 | 610 | * |
|
229 | 140 | * @return array |
|
230 | 140 | */ |
|
231 | 140 | private function fixConfigFilebrowsers(array $config, array $filebrowsers) |
|
269 | |||
270 | /** |
||
271 | * @param JsonBuilder $builder |
||
272 | * @param array $config |
||
273 | */ |
||
274 | 610 | private function fixConfigEscapedValues(JsonBuilder $builder, array $config) |
|
293 | |||
294 | 190 | /** |
|
295 | 50 | * @param string $json |
|
296 | 40 | * |
|
297 | * @return string |
||
298 | 190 | */ |
|
299 | private function fixConfigConstants($json) |
||
303 | |||
304 | 680 | /** |
|
305 | * @param string $path |
||
306 | 680 | * |
|
307 | * @return string |
||
308 | */ |
||
309 | private function fixPath($path) |
||
323 | |||
324 | /** |
||
325 | * @return \Twig_Environment|EngineInterface |
||
326 | 590 | */ |
|
327 | private function getTemplating() |
||
333 | } |
||
334 |