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 | public function __construct(ContainerInterface $container) |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | public function renderBasePath($basePath) |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | public function renderJsPath($jsPath) |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc} |
||
58 | */ |
||
59 | public function renderWidget($id, array $config, array $options = array()) |
||
94 | |||
95 | /** |
||
96 | * {@inheritdoc} |
||
97 | */ |
||
98 | public function renderDestroy($id) |
||
102 | |||
103 | /** |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | public function renderPlugin($name, array $plugin) |
||
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | */ |
||
119 | public function renderStylesSet($name, array $stylesSet) |
||
132 | |||
133 | /** |
||
134 | * {@inheritdoc} |
||
135 | */ |
||
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 | 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 | 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 | private function fixConfigFilebrowsers(array $config, array $filebrowsers) |
||
256 | |||
257 | /** |
||
258 | * Fixes the config escaped values and sets them on the json builder. |
||
259 | * |
||
260 | * @param array $config The config. |
||
261 | */ |
||
262 | private function fixConfigEscapedValues(array $config) |
||
281 | |||
282 | /** |
||
283 | * Fixes the config constants. |
||
284 | * |
||
285 | * @param string $json The json config. |
||
286 | * |
||
287 | * @return string The fixed config. |
||
288 | */ |
||
289 | private function fixConfigConstants($json) |
||
293 | |||
294 | /** |
||
295 | * Fixes a path. |
||
296 | * |
||
297 | * @param string $path The path. |
||
298 | * |
||
299 | * @return string The fixed path. |
||
300 | */ |
||
301 | private function fixPath($path) |
||
309 | |||
310 | /** |
||
311 | * Fixes an url. |
||
312 | * |
||
313 | * @param string $url The url. |
||
314 | * |
||
315 | * @return string The fixed url. |
||
316 | */ |
||
317 | private function fixUrl($url) |
||
327 | |||
328 | /** |
||
329 | * Gets the locale. |
||
330 | * |
||
331 | * @return string|null The locale. |
||
332 | */ |
||
333 | private function getLanguage() |
||
343 | |||
344 | /** |
||
345 | * Gets the request. |
||
346 | * |
||
347 | * @return \Symfony\Component\HttpFoundation\Request The request. |
||
348 | */ |
||
349 | private function getRequest() |
||
359 | |||
360 | /** |
||
361 | * Gets the templating engine. |
||
362 | * |
||
363 | * @return \Symfony\Component\Templating\EngineInterface|\Twig_Environment The templating engine. |
||
364 | */ |
||
365 | private function getTemplating() |
||
373 | |||
374 | /** |
||
375 | * Gets the assets helper. |
||
376 | * |
||
377 | * @return \Symfony\Component\Asset\Packages|\Symfony\Component\Templating\Helper\CoreAssetsHelper|null The assets helper. |
||
378 | */ |
||
379 | private function getAssetsHelper() |
||
383 | |||
384 | /** |
||
385 | * Gets the router. |
||
386 | * |
||
387 | * @return \Symfony\Component\Routing\RouterInterface The router. |
||
388 | */ |
||
389 | private function getRouter() |
||
393 | } |
||
394 |