Complex classes like SilverstripePage 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 SilverstripePage, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | class SilverstripePage |
||
| 10 | {
|
||
| 11 | private $path_configphp; |
||
| 12 | private $path_project; |
||
| 13 | private $path_configyml; |
||
| 14 | private $path_root; |
||
| 15 | private $path_ssversion; |
||
| 16 | private $path_composer; |
||
| 17 | private $name; |
||
| 18 | private $version; |
||
| 19 | private $defadmin; |
||
| 20 | private $maillog; |
||
| 21 | private $envtype; |
||
| 22 | private $modules; |
||
| 23 | |||
| 24 | public function __construct(SiteConfig $sc) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * gets the path of all required files and folders. |
||
| 39 | * |
||
| 40 | * @param string $path |
||
| 41 | * |
||
| 42 | * @return boolean |
||
| 43 | */ |
||
| 44 | public function setupPaths($path) |
||
| 55 | |||
| 56 | public function reload() |
||
| 64 | |||
| 65 | private function readVersion() |
||
| 96 | |||
| 97 | private function readDefaultAdmin() |
||
| 102 | |||
| 103 | private function readEmailLogging() |
||
| 108 | |||
| 109 | private function readEnvironmentType() |
||
| 134 | |||
| 135 | private function readModules() |
||
| 159 | |||
| 160 | /** |
||
| 161 | * searches for a regex string in PROJECT/_config.php. |
||
| 162 | * |
||
| 163 | * @param string $regex |
||
| 164 | * |
||
| 165 | * @return boolean|array |
||
| 166 | */ |
||
| 167 | private function matchInConfigPhp($regex) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @param string $regex |
||
| 183 | * @return bool |
||
| 184 | */ |
||
| 185 | public function hasModule($regex) |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @return string |
||
| 198 | */ |
||
| 199 | public function getName() |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @return string |
||
| 206 | */ |
||
| 207 | public function getVersion() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @return boolean indicates if a DefaultAdmin is specified |
||
| 214 | */ |
||
| 215 | public function hasDefaultAdmin() |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @return boolean indicates if EmailLogging is activated |
||
| 222 | */ |
||
| 223 | public function hasEmailLogging() |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @return string with the EnvironmentType |
||
| 230 | */ |
||
| 231 | public function getEnvironmentType() |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @return array with the module folder names |
||
| 238 | */ |
||
| 239 | public function getModules() |
||
| 243 | |||
| 244 | public function getConfigPhpPath() |
||
| 248 | |||
| 249 | public function getConfigYmlPath() |
||
| 253 | |||
| 254 | public function getRootPath() |
||
| 258 | } |
||
| 259 |