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 |
||
21 | class CKEditorRenderer implements CKEditorRendererInterface |
||
22 | { |
||
23 | /** @var \Ivory\JsonBuilder\JsonBuilder */ |
||
24 | private $jsonBuilder; |
||
25 | |||
26 | /** @var \Symfony\Component\DependencyInjection\ContainerInterface */ |
||
27 | private $container; |
||
28 | |||
29 | /** |
||
30 | * Creates a CKEditor renderer. |
||
31 | * |
||
32 | * @param \Symfony\Component\DependencyInjection\ContainerInterface $container The container. |
||
33 | */ |
||
34 | 1392 | public function __construct(ContainerInterface $container) |
|
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | 170 | public function renderBasePath($basePath) |
|
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | 153 | public function renderJsPath($jsPath) |
|
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | 1069 | public function renderWidget($id, array $config, array $options = array()) |
|
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | 187 | public function renderDestroy($id) |
|
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | 68 | public function renderPlugin($name, array $plugin) |
|
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | */ |
||
119 | 51 | public function renderStylesSet($name, array $stylesSet) |
|
132 | |||
133 | /** |
||
134 | * {@inheritdoc} |
||
135 | */ |
||
136 | 136 | public function renderTemplate($name, array $template) |
|
162 | |||
163 | /** |
||
164 | * Fixes the config language. |
||
165 | * |
||
166 | * @param array $config The config. |
||
167 | * |
||
168 | * @return array The fixed config. |
||
169 | */ |
||
170 | 1069 | private function fixConfigLanguage(array $config) |
|
182 | |||
183 | /** |
||
184 | * Fixes the config contents css. |
||
185 | * |
||
186 | * @param array $config The config. |
||
187 | * |
||
188 | * @return array The fixed config. |
||
189 | */ |
||
190 | 1069 | private function fixConfigContentsCss(array $config) |
|
203 | |||
204 | /** |
||
205 | * Fixes the config filebrowsers. |
||
206 | * |
||
207 | * @param array $config The config. |
||
208 | * @param array $filebrowsers The filebrowsers. |
||
209 | * |
||
210 | * @return array The fixed config. |
||
211 | */ |
||
212 | 1069 | private function fixConfigFilebrowsers(array $config, array $filebrowsers) |
|
250 | |||
251 | /** |
||
252 | * Fixes the config escaped values and sets them on the json builder. |
||
253 | * |
||
254 | * @param array $config The config. |
||
255 | */ |
||
256 | 1069 | private function fixConfigEscapedValues(array $config) |
|
275 | |||
276 | /** |
||
277 | * Fixes the config constants. |
||
278 | * |
||
279 | * @param string $json The json config. |
||
280 | * |
||
281 | * @return string The fixed config. |
||
282 | */ |
||
283 | 1069 | private function fixConfigConstants($json) |
|
287 | |||
288 | /** |
||
289 | * Fixes a path. |
||
290 | * |
||
291 | * @param string $path The path. |
||
292 | * |
||
293 | * @return string The fixed path. |
||
294 | */ |
||
295 | 442 | private function fixPath($path) |
|
303 | |||
304 | /** |
||
305 | * Fixes an url. |
||
306 | * |
||
307 | * @param string $url The url. |
||
308 | * |
||
309 | * @return string The fixed url. |
||
310 | */ |
||
311 | 459 | private function fixUrl($url) |
|
317 | |||
318 | /** |
||
319 | * @param bool $routePath |
||
320 | * |
||
321 | * @return int|bool |
||
322 | */ |
||
323 | 238 | private function fixRoutePath($routePath) |
|
335 | |||
336 | /** |
||
337 | * Gets the locale. |
||
338 | * |
||
339 | * @return string|null The locale. |
||
340 | */ |
||
341 | 1035 | private function getLanguage() |
|
351 | |||
352 | /** |
||
353 | * Gets the request. |
||
354 | * |
||
355 | * @return \Symfony\Component\HttpFoundation\Request|null The request. |
||
356 | */ |
||
357 | 1035 | private function getRequest() |
|
367 | |||
368 | /** |
||
369 | * Gets the templating engine. |
||
370 | * |
||
371 | * @return \Symfony\Component\Templating\EngineInterface|\Twig_Environment The templating engine. |
||
372 | */ |
||
373 | 68 | private function getTemplating() |
|
379 | |||
380 | /** |
||
381 | * Gets the assets helper. |
||
382 | * |
||
383 | * @return \Symfony\Component\Asset\Packages|\Symfony\Component\Templating\Helper\CoreAssetsHelper|null The assets helper. |
||
384 | */ |
||
385 | 459 | private function getAssetsHelper() |
|
389 | |||
390 | /** |
||
391 | * Gets the router. |
||
392 | * |
||
393 | * @return \Symfony\Component\Routing\RouterInterface The router. |
||
394 | */ |
||
395 | 357 | private function getRouter() |
|
399 | } |
||
400 |