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) |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Fixes the config language. |
||
| 176 | * |
||
| 177 | * @param array $config The config. |
||
| 178 | * |
||
| 179 | * @return array The fixed config. |
||
| 180 | */ |
||
| 181 | private function fixConfigLanguage(array $config) |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Fixes the config contents css. |
||
| 192 | * |
||
| 193 | * @param array $config The config. |
||
| 194 | * |
||
| 195 | * @return array The fixed config. |
||
| 196 | */ |
||
| 197 | private function fixConfigContentsCss(array $config) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Fixes the config filebrowsers. |
||
| 213 | * |
||
| 214 | * @param array $config The config. |
||
| 215 | * @param array $filebrowsers The filebrowsers. |
||
| 216 | * |
||
| 217 | * @return array The fixed config. |
||
| 218 | */ |
||
| 219 | private function fixConfigFilebrowsers(array $config, array $filebrowsers) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * Fixes the config escaped values and sets them on the json builder. |
||
| 266 | * |
||
| 267 | * @param array $config The config. |
||
| 268 | */ |
||
| 269 | private function fixConfigEscapedValues(array $config) |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Fixes the config constants. |
||
| 291 | * |
||
| 292 | * @param string $json The json config. |
||
| 293 | * |
||
| 294 | * @return string The fixed config. |
||
| 295 | */ |
||
| 296 | private function fixConfigConstants($json) |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Fixes a path. |
||
| 303 | * |
||
| 304 | * @param string $path The path. |
||
| 305 | * |
||
| 306 | * @return string The fixed path. |
||
| 307 | */ |
||
| 308 | private function fixPath($path) |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Fixes an url. |
||
| 319 | * |
||
| 320 | * @param string $url The url. |
||
| 321 | * |
||
| 322 | * @return string The fixed url. |
||
| 323 | */ |
||
| 324 | private function fixUrl($url) |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Gets the assets helper. |
||
| 337 | * |
||
| 338 | * @return \Symfony\Component\Asset\Packages|\Symfony\Component\Templating\Helper\CoreAssetsHelper|null The assets helper. |
||
| 339 | */ |
||
| 340 | private function getAssetsHelper() |
||
| 344 | |||
| 345 | /** |
||
| 346 | * Gets the router. |
||
| 347 | * |
||
| 348 | * @return \Symfony\Component\Routing\RouterInterface The router. |
||
| 349 | */ |
||
| 350 | private function getRouter() |
||
| 354 | } |
||
| 355 |