Complex classes like MappingA 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 MappingA, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 17 | abstract class MappingA extends Object { |
||
| 18 | /** |
||
| 19 | * @var string |
||
| 20 | */ |
||
| 21 | private $sRegex; |
||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | private $sPath; |
||
| 26 | /** |
||
| 27 | * @var string |
||
| 28 | */ |
||
| 29 | private $sTemplate; |
||
| 30 | /** |
||
| 31 | * the local template path - will be used to compose something like |
||
| 32 | * this->sViewPath . view->typeOfView . this->sTemplate |
||
| 33 | * |
||
| 34 | * @var string |
||
| 35 | */ |
||
| 36 | private $sViewPath; |
||
| 37 | |||
| 38 | private $bIsStatic = false; |
||
| 39 | |||
| 40 | private $aControllerMaps = array(); |
||
| 41 | |||
| 42 | private $aTaintedVars = []; |
||
| 43 | |||
| 44 | private $sMatchingUrl; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var int |
||
| 48 | */ |
||
| 49 | private $iAuthenticationType = null; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param MappingA $oMap |
||
| 53 | */ |
||
| 54 | abstract protected function mergeResources($oMap); |
||
| 55 | /** |
||
| 56 | * @return string |
||
| 57 | */ |
||
| 58 | abstract public function getTitle(); |
||
| 59 | /** |
||
| 60 | * @param string $sTitle |
||
| 61 | */ |
||
| 62 | abstract public function setTitle($sTitle); |
||
| 63 | /** |
||
| 64 | * @param string $sPath |
||
| 65 | * @param string $sRegex |
||
| 66 | */ |
||
| 67 | 24 | public function __construct($sPath, $sRegex) { |
|
| 71 | |||
| 72 | 20 | public function getRegex() { |
|
| 75 | |||
| 76 | /** |
||
| 77 | * @param bool $bStatic |
||
| 78 | */ |
||
| 79 | 2 | public function setIsStatic($bStatic) { |
|
| 82 | |||
| 83 | /** |
||
| 84 | * @return bool |
||
| 85 | */ |
||
| 86 | 2 | public function isStatic() { |
|
| 89 | |||
| 90 | /** |
||
| 91 | * @param MappingA $oMap |
||
| 92 | */ |
||
| 93 | 21 | protected function mergePaths($oMap) { |
|
| 116 | |||
| 117 | /** |
||
| 118 | * @param MappingA $oMap |
||
| 119 | * @return $this |
||
| 120 | */ |
||
| 121 | 20 | public function merge($oMap = null) { |
|
| 135 | |||
| 136 | /** |
||
| 137 | * @param string $sPath |
||
| 138 | * @return bool |
||
| 139 | * @throws ExceptionSitemap |
||
| 140 | */ |
||
| 141 | 21 | public function setTemplatePath($sPath) { |
|
| 144 | |||
| 145 | /** |
||
| 146 | * @return string |
||
| 147 | */ |
||
| 148 | 21 | public function getTemplatePath() { |
|
| 151 | |||
| 152 | /** |
||
| 153 | * @param string $sPath |
||
| 154 | */ |
||
| 155 | 18 | public function setTemplate($sPath) { |
|
| 158 | |||
| 159 | /** |
||
| 160 | * @return string |
||
| 161 | */ |
||
| 162 | 19 | public function getTemplate() { |
|
| 165 | |||
| 166 | /** |
||
| 167 | * @return string |
||
| 168 | */ |
||
| 169 | 24 | public function getPath() { |
|
| 172 | |||
| 173 | /** |
||
| 174 | * @deprecated |
||
| 175 | * @param string $sRegex |
||
| 176 | * @param string $sPath |
||
| 177 | * @throws ExceptionController |
||
| 178 | * @throws ExceptionSitemap |
||
| 179 | * @returns ClassMap |
||
| 180 | */ |
||
| 181 | public function mapController($sRegex, $sPath = null) { |
||
| 184 | |||
| 185 | /** |
||
| 186 | * |
||
| 187 | * @param string $sRegex |
||
| 188 | * @param string $sPath |
||
| 189 | * @throws ExceptionController |
||
| 190 | * @throws ExceptionSitemap |
||
| 191 | * @returns ClassMap |
||
| 192 | */ |
||
| 193 | 22 | public function map($sRegex, $sPath = null) { |
|
| 218 | |||
| 219 | /** |
||
| 220 | * @return MappingA[] |
||
| 221 | */ |
||
| 222 | 20 | public function getControllerMaps() { |
|
| 225 | |||
| 226 | /** |
||
| 227 | * @param string[] $aVars |
||
| 228 | */ |
||
| 229 | 18 | public function setTaintedVars($aVars) { |
|
| 232 | |||
| 233 | 10 | public function getTaintedVars() { |
|
| 236 | |||
| 237 | /** |
||
| 238 | * @param string $sUrl |
||
| 239 | */ |
||
| 240 | 19 | public function setUrl($sUrl) { |
|
| 243 | |||
| 244 | /** |
||
| 245 | * @returns Url |
||
| 246 | */ |
||
| 247 | 2 | public function getUrl() { |
|
| 259 | |||
| 260 | 2 | public function setAuthenticationType($iAuthenticationType) { |
|
| 263 | |||
| 264 | 22 | public function getAuthenticationType() { |
|
| 267 | |||
| 268 | /** |
||
| 269 | * @return string |
||
| 270 | */ |
||
| 271 | 1 | public function getValidAuthenticationSchemas() { |
|
| 274 | |||
| 275 | /** |
||
| 276 | * @return bool |
||
| 277 | */ |
||
| 278 | 2 | public function requiresAuthentication() { |
|
| 281 | |||
| 282 | /** |
||
| 283 | * @param Object $mappedObject |
||
| 284 | * @return boolean |
||
| 285 | */ |
||
| 286 | 1 | public function maps(Object $mappedObject) |
|
| 290 | |||
| 291 | /** |
||
| 292 | * @param string $sPath |
||
| 293 | * @return string |
||
| 294 | * @throws ExceptionSitemap |
||
| 295 | */ |
||
| 296 | 21 | protected function getValidPath($sPath) { |
|
| 310 | } |
||
| 311 | |||
| 312 |
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@returndoc comment to communicate to implementors of these methods what they are expected to return.