| Total Complexity | 47 |
| Total Lines | 122 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like GenericPhysicalAddress 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.
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 GenericPhysicalAddress, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 18 | class GenericPhysicalAddress implements PhysicalAddress |
||
| 19 | { |
||
| 20 | /** @var \Talentify\ValueObject\Geography\Address\Street|null */ |
||
| 21 | protected $street; |
||
| 22 | /** @var \Talentify\ValueObject\Geography\Address\City|null */ |
||
| 23 | protected $city; |
||
| 24 | /** @var \Talentify\ValueObject\Geography\Address\Region|null */ |
||
| 25 | protected $region; |
||
| 26 | /** @var \Talentify\ValueObject\Geography\Address\PostalCode|null */ |
||
| 27 | protected $postalCode; |
||
| 28 | /** @var \Talentify\ValueObject\Geography\Address\Country|null */ |
||
| 29 | protected $country; |
||
| 30 | /** @var string */ |
||
| 31 | protected $formattedAddress; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @throws \InvalidArgumentException |
||
| 35 | */ |
||
| 36 | public function __construct( |
||
| 50 | } |
||
| 51 | |||
| 52 | public function getStreet() : ?Street |
||
| 53 | { |
||
| 54 | return $this->street; |
||
| 55 | } |
||
| 56 | |||
| 57 | public function getCity() : ?City |
||
| 60 | } |
||
| 61 | |||
| 62 | public function getRegion() : ?Region |
||
| 63 | { |
||
| 64 | return $this->region; |
||
| 65 | } |
||
| 66 | |||
| 67 | public function getCountry() : ?Country |
||
| 68 | { |
||
| 69 | return $this->country; |
||
| 70 | } |
||
| 71 | |||
| 72 | public function getPostalCode() : ?PostalCode |
||
| 75 | } |
||
| 76 | |||
| 77 | public function equals(?ValueObject $object) : bool |
||
| 108 | ) |
||
| 109 | ); |
||
| 110 | } |
||
| 111 | |||
| 112 | public function getAddress() : string |
||
| 135 | } |
||
| 136 | |||
| 137 | public function __toString() : string |
||
| 142 |