Complex classes like RootConfig 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 RootConfig, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 6 | class RootConfig extends IndexConfig |
||
| 7 | { |
||
| 8 | protected $target; |
||
| 9 | protected $conversionProcess; |
||
| 10 | protected $renderingProcess; |
||
| 11 | protected $tocProcess; |
||
| 12 | protected $headingsProcess; |
||
| 13 | protected $copyImageProcess; |
||
| 14 | protected $copyrightProcess; |
||
| 15 | protected $template; |
||
| 16 | protected $rootHref; |
||
| 17 | protected $tocDepth; |
||
| 18 | protected $copyright; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var array |
||
| 22 | */ |
||
| 23 | protected $commonMarkExtensions = array(); |
||
| 24 | |||
| 25 | 5 | public function setOverrides(array $overrides) |
|
| 31 | |||
| 32 | 2 | protected function setOverride($key, $val) |
|
| 56 | |||
| 57 | 29 | protected function init() |
|
| 73 | |||
| 74 | 29 | protected function initTarget() |
|
| 84 | |||
| 85 | 28 | protected function initRootHref() |
|
| 91 | |||
| 92 | 28 | protected function initCommonMarkExtensions() |
|
| 110 | |||
| 111 | 28 | protected function initTemplate() |
|
| 117 | |||
| 118 | 29 | protected function initTocDepth() |
|
| 124 | |||
| 125 | 28 | protected function initCopyright() |
|
| 131 | |||
| 132 | |||
| 133 | 28 | protected function initConversionProcess() |
|
| 139 | |||
| 140 | 28 | protected function initHeadingsProcess() |
|
| 146 | |||
| 147 | 28 | protected function initCopyImageProcess() |
|
| 153 | |||
| 154 | 28 | protected function initCopyrightProcess() |
|
| 160 | |||
| 161 | 28 | protected function initTocProcess() |
|
| 167 | |||
| 168 | 28 | protected function initRenderingProcess() |
|
| 174 | |||
| 175 | 19 | public function getConversionProcess() |
|
| 179 | |||
| 180 | 16 | public function getHeadingsProcess() |
|
| 184 | |||
| 185 | 3 | public function getCopyImageProcess() |
|
| 189 | |||
| 190 | 3 | public function getCopyrightProcess() |
|
| 194 | |||
| 195 | 15 | public function getTocProcess() |
|
| 199 | |||
| 200 | 5 | public function getRenderingProcess() |
|
| 204 | |||
| 205 | 24 | public function getTarget() |
|
| 209 | |||
| 210 | 19 | public function getRootHref() |
|
| 214 | |||
| 215 | 6 | public function getTemplate() |
|
| 219 | |||
| 220 | 6 | public function getTocDepth() |
|
| 224 | |||
| 225 | 2 | public function getCopyright() |
|
| 229 | |||
| 230 | 1 | public function get($key, $alt = null) |
|
| 237 | |||
| 238 | /** |
||
| 239 | * @return array |
||
| 240 | */ |
||
| 241 | 18 | public function getCommonMarkExtensions() |
|
| 245 | } |
||
| 246 |