Complex classes like Lead 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 Lead, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 11 | class Lead extends Model |
||
| 12 | { |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @var integer |
||
| 16 | */ |
||
| 17 | protected $id; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var integer |
||
| 21 | */ |
||
| 22 | protected $contactId; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | protected $name; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var integer |
||
| 31 | */ |
||
| 32 | protected $funnelId; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var View |
||
| 36 | */ |
||
| 37 | protected $view; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var integer |
||
| 41 | */ |
||
| 42 | protected $ownerId; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var \DateTime |
||
| 46 | */ |
||
| 47 | protected $createdAt; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var Payment[] |
||
| 51 | */ |
||
| 52 | protected $payments = []; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var Custom[] |
||
| 56 | */ |
||
| 57 | protected $customs = []; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var array |
||
| 61 | */ |
||
| 62 | protected $options = []; |
||
| 63 | |||
| 64 | |||
| 65 | /** |
||
| 66 | * Lead constructor. |
||
| 67 | * |
||
| 68 | * @param array $leadData |
||
| 69 | */ |
||
| 70 | public function __construct(array $leadData = []) |
||
| 113 | |||
| 114 | |||
| 115 | /** |
||
| 116 | * @param bool $toSave |
||
| 117 | * |
||
| 118 | * @return array |
||
| 119 | */ |
||
| 120 | public function toArray($toSave = false) |
||
| 159 | |||
| 160 | |||
| 161 | /** |
||
| 162 | * @return bool |
||
| 163 | * @throws LPTrackerSDKException |
||
| 164 | */ |
||
| 165 | public function validate() |
||
| 185 | |||
| 186 | |||
| 187 | /** |
||
| 188 | * @return int |
||
| 189 | */ |
||
| 190 | public function getId() |
||
| 194 | |||
| 195 | |||
| 196 | /** |
||
| 197 | * @return int |
||
| 198 | */ |
||
| 199 | public function getContactId() |
||
| 203 | |||
| 204 | |||
| 205 | /** |
||
| 206 | * @return string |
||
| 207 | */ |
||
| 208 | public function getName() |
||
| 212 | |||
| 213 | |||
| 214 | /** |
||
| 215 | * @param string $name |
||
| 216 | * |
||
| 217 | * @return $this |
||
| 218 | */ |
||
| 219 | public function setName($name) |
||
| 225 | |||
| 226 | |||
| 227 | /** |
||
| 228 | * @return int |
||
| 229 | */ |
||
| 230 | public function getFunnelId() |
||
| 234 | |||
| 235 | |||
| 236 | /** |
||
| 237 | * @param int $funnelId |
||
| 238 | * |
||
| 239 | * @return $this |
||
| 240 | */ |
||
| 241 | public function setFunnelId($funnelId) |
||
| 247 | |||
| 248 | |||
| 249 | /** |
||
| 250 | * @return View |
||
| 251 | */ |
||
| 252 | public function getView() |
||
| 256 | |||
| 257 | |||
| 258 | /** |
||
| 259 | * @param View $view |
||
| 260 | * |
||
| 261 | * @return $this |
||
| 262 | */ |
||
| 263 | public function setView(View $view) |
||
| 269 | |||
| 270 | |||
| 271 | /** |
||
| 272 | * @return Payment[] |
||
| 273 | */ |
||
| 274 | public function getPayments() |
||
| 278 | |||
| 279 | |||
| 280 | /** |
||
| 281 | * @param array $payments |
||
| 282 | * |
||
| 283 | * @return $this |
||
| 284 | */ |
||
| 285 | public function setPayments(array $payments) |
||
| 291 | |||
| 292 | |||
| 293 | /** |
||
| 294 | * @param Payment $payment |
||
| 295 | * |
||
| 296 | * @return $this |
||
| 297 | */ |
||
| 298 | public function addPayment(Payment $payment) |
||
| 304 | |||
| 305 | |||
| 306 | /** |
||
| 307 | * @return int |
||
| 308 | */ |
||
| 309 | public function getOwnerId() |
||
| 313 | |||
| 314 | |||
| 315 | /** |
||
| 316 | * @param int $ownerId |
||
| 317 | * |
||
| 318 | * @return $this |
||
| 319 | */ |
||
| 320 | public function setOwnerId($ownerId) |
||
| 326 | |||
| 327 | |||
| 328 | /** |
||
| 329 | * @return Custom[] |
||
| 330 | */ |
||
| 331 | public function getCustoms() |
||
| 335 | |||
| 336 | |||
| 337 | /** |
||
| 338 | * @param Custom[] $customs |
||
| 339 | * |
||
| 340 | * @return $this |
||
| 341 | */ |
||
| 342 | public function setCustoms(array $customs) |
||
| 348 | |||
| 349 | |||
| 350 | /** |
||
| 351 | * @param Custom $custom |
||
| 352 | * |
||
| 353 | * @return $this |
||
| 354 | */ |
||
| 355 | public function addCustom(Custom $custom) |
||
| 361 | |||
| 362 | |||
| 363 | /** |
||
| 364 | * @return \DateTime |
||
| 365 | */ |
||
| 366 | public function getCreatedAt() |
||
| 370 | |||
| 371 | |||
| 372 | /** |
||
| 373 | * @param \DateTime $createdAt |
||
| 374 | * |
||
| 375 | * @return $this |
||
| 376 | */ |
||
| 377 | public function setCreatedAt($createdAt) |
||
| 383 | } |