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 BaseObject { |
||
| 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 | 21 | public function merge($oMap = null) { |
|
| 136 | |||
| 137 | /** |
||
| 138 | * @param string $sPath |
||
| 139 | * @return bool |
||
| 140 | * @throws ExceptionSitemap |
||
| 141 | */ |
||
| 142 | 21 | public function setTemplatePath($sPath) { |
|
| 145 | |||
| 146 | /** |
||
| 147 | * @return string |
||
| 148 | */ |
||
| 149 | 21 | public function getTemplatePath() { |
|
| 152 | |||
| 153 | /** |
||
| 154 | * @param string $sPath |
||
| 155 | */ |
||
| 156 | 18 | public function setTemplate($sPath) { |
|
| 159 | |||
| 160 | /** |
||
| 161 | * @return string |
||
| 162 | */ |
||
| 163 | 19 | public function getTemplate() { |
|
| 166 | |||
| 167 | /** |
||
| 168 | * @return string |
||
| 169 | */ |
||
| 170 | 24 | public function getPath() { |
|
| 173 | |||
| 174 | /** |
||
| 175 | * @deprecated |
||
| 176 | * @param string $sRegex |
||
| 177 | * @param string $sPath |
||
| 178 | * @throws ExceptionController |
||
| 179 | * @throws ExceptionSitemap |
||
| 180 | * @returns ClassMap |
||
| 181 | */ |
||
| 182 | public function mapController($sRegex, $sPath = null) { |
||
| 185 | |||
| 186 | /** |
||
| 187 | * |
||
| 188 | * @param string $sRegex |
||
| 189 | * @param string $sPath |
||
| 190 | * @throws ExceptionController |
||
| 191 | * @throws ExceptionSitemap |
||
| 192 | * @returns ClassMap |
||
| 193 | */ |
||
| 194 | 22 | public function map($sRegex, $sPath = null) { |
|
| 219 | |||
| 220 | /** |
||
| 221 | * @return MappingA[] |
||
| 222 | */ |
||
| 223 | 20 | public function getControllerMaps() { |
|
| 226 | |||
| 227 | /** |
||
| 228 | * @param string[] $aVars |
||
| 229 | */ |
||
| 230 | 18 | public function setTaintedVars($aVars) { |
|
| 233 | |||
| 234 | 10 | public function getTaintedVars() { |
|
| 237 | |||
| 238 | /** |
||
| 239 | * @param string $sUrl |
||
| 240 | */ |
||
| 241 | 19 | public function setUrl($sUrl) { |
|
| 244 | |||
| 245 | /** |
||
| 246 | * @returns Url |
||
| 247 | */ |
||
| 248 | 2 | public function getUrl() { |
|
| 260 | |||
| 261 | 2 | public function setAuthenticationType($iAuthenticationType) { |
|
| 264 | |||
| 265 | 22 | public function getAuthenticationType() { |
|
| 268 | |||
| 269 | /** |
||
| 270 | * @return string |
||
| 271 | */ |
||
| 272 | 1 | public function getValidAuthenticationSchemas() { |
|
| 275 | |||
| 276 | /** |
||
| 277 | * @return bool |
||
| 278 | */ |
||
| 279 | 2 | public function requiresAuthentication() { |
|
| 282 | |||
| 283 | /** |
||
| 284 | * @param Object $mappedObject |
||
| 285 | * @return boolean |
||
| 286 | */ |
||
| 287 | 1 | public function maps(BaseObject $mappedObject) |
|
| 291 | |||
| 292 | /** |
||
| 293 | * @param string $sPath |
||
| 294 | * @return string |
||
| 295 | * @throws ExceptionSitemap |
||
| 296 | */ |
||
| 297 | 21 | protected function getValidPath($sPath) { |
|
| 311 | } |
||
| 312 | |||
| 313 |
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.