Complex classes like View 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 View, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class View extends Model |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var integer |
||
| 11 | */ |
||
| 12 | protected $id; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | protected $uuid; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | protected $ymClientId; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $gaClientId; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var integer |
||
| 31 | */ |
||
| 32 | protected $projectId; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $source; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var string |
||
| 41 | */ |
||
| 42 | protected $campaign; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var string |
||
| 46 | */ |
||
| 47 | protected $keyword; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var string |
||
| 51 | */ |
||
| 52 | protected $seoSystem; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | protected $page; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | protected $referer; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var Visitor|null |
||
| 66 | */ |
||
| 67 | protected $visitor; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var Visitor|null |
||
| 71 | */ |
||
| 72 | protected $realVisitor; |
||
| 73 | |||
| 74 | public function __construct(array $viewData = []) |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @return bool |
||
| 119 | * @throws LPTrackerSDKException |
||
| 120 | */ |
||
| 121 | public function validate() |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @return array |
||
| 138 | */ |
||
| 139 | public function toArray() |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @return int |
||
| 165 | */ |
||
| 166 | public function getId() |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @return int |
||
| 173 | */ |
||
| 174 | public function getProjectId() |
||
| 178 | |||
| 179 | /** |
||
| 180 | * @return string |
||
| 181 | */ |
||
| 182 | public function getSource() |
||
| 186 | |||
| 187 | /** |
||
| 188 | * @param string $source |
||
| 189 | * @return $this |
||
| 190 | */ |
||
| 191 | public function setSource($source) |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @return string |
||
| 199 | */ |
||
| 200 | public function getCampaign() |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @param string $campaign |
||
| 207 | * @return $this |
||
| 208 | */ |
||
| 209 | public function setCampaign($campaign) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * @return string |
||
| 217 | */ |
||
| 218 | public function getKeyword() |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @param string $keyword |
||
| 225 | * @return $this |
||
| 226 | */ |
||
| 227 | public function setKeyword($keyword) |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @return string |
||
| 235 | */ |
||
| 236 | public function getSeoSystem() |
||
| 240 | |||
| 241 | /** |
||
| 242 | * @param string $seoSystem |
||
| 243 | * @return $this |
||
| 244 | */ |
||
| 245 | public function setSeoSystem($seoSystem) |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @return string |
||
| 253 | */ |
||
| 254 | public function getPage() |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @param string $page |
||
| 261 | * @return $this |
||
| 262 | */ |
||
| 263 | public function setPage($page) |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @return string |
||
| 271 | */ |
||
| 272 | public function getReferer() |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @param string $referer |
||
| 279 | * @return $this |
||
| 280 | */ |
||
| 281 | public function setReferer($referer) |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @return string |
||
| 289 | */ |
||
| 290 | public function getUuid() |
||
| 294 | |||
| 295 | /** |
||
| 296 | * @return string |
||
| 297 | */ |
||
| 298 | public function getYmClientId() |
||
| 302 | |||
| 303 | /** |
||
| 304 | * @return string |
||
| 305 | */ |
||
| 306 | public function getGaClientId() |
||
| 310 | |||
| 311 | /** |
||
| 312 | * @return Visitor|null |
||
| 313 | */ |
||
| 314 | public function getVisitor() |
||
| 318 | |||
| 319 | /** |
||
| 320 | * @return Visitor|null |
||
| 321 | */ |
||
| 322 | public function getRealVisitor() |
||
| 326 | } |
||
| 327 |