| Total Complexity | 51 |
| Total Lines | 163 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like BrPhysicalAddress 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 BrPhysicalAddress, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 27 | final class BrPhysicalAddress implements PhysicalAddress |
||
| 28 | { |
||
| 29 | /** @var \Talentify\ValueObject\Geography\Address\ByCountry\Br\Street|null */ |
||
| 30 | private $street; |
||
| 31 | /** @var \Talentify\ValueObject\Geography\Address\ByCountry\Br\Neighbourhood|null */ |
||
| 32 | private $neighbourhood; |
||
| 33 | /** @var \Talentify\ValueObject\Geography\Address\ByCountry\Br\Municipality|null */ |
||
| 34 | private $municipality; |
||
| 35 | /** @var \Talentify\ValueObject\Geography\Address\ByCountry\Br\State|null */ |
||
| 36 | private $state; |
||
| 37 | /** @var \Talentify\ValueObject\Geography\Address\ByCountry\Br\CEP|null */ |
||
| 38 | private $postalCode; |
||
| 39 | /** @var \Talentify\ValueObject\Geography\Address\Country */ |
||
| 40 | private $country; |
||
| 41 | /** @var string */ |
||
| 42 | private $formattedAddress; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @throws \InvalidArgumentException |
||
| 46 | */ |
||
| 47 | public function __construct( |
||
| 48 | ?BrStreet $street = null, |
||
| 49 | ?BrNeighbourhood $neighbourhood = null, |
||
| 50 | ?Municipality $municipality = null, |
||
| 51 | ?BrState $state = null, |
||
| 52 | ?BrPostalCode $postalCode = null, |
||
| 53 | ?string $formattedAddress = null |
||
| 54 | ) { |
||
| 55 | $this->street = $street; |
||
| 56 | $this->neighbourhood = $neighbourhood; |
||
| 57 | $this->municipality = $municipality; |
||
| 58 | $this->state = $state; |
||
| 59 | $this->postalCode = $postalCode; |
||
| 60 | $this->country = CountryList::BR(); |
||
| 61 | $this->formattedAddress = $formattedAddress; |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @return \Talentify\ValueObject\Geography\Address\ByCountry\Br\Street |
||
| 66 | */ |
||
| 67 | public function getStreet() : ?BaseStreet |
||
| 68 | { |
||
| 69 | return $this->street; |
||
| 70 | } |
||
| 71 | |||
| 72 | public function getNeighbourhood() : ?BrNeighbourhood |
||
| 73 | { |
||
| 74 | return $this->neighbourhood; |
||
| 75 | } |
||
| 76 | |||
| 77 | public function getMunicipality() : ?Municipality |
||
| 78 | { |
||
| 79 | return $this->municipality; |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @return \Talentify\ValueObject\Geography\Address\ByCountry\Br\Municipality|null |
||
| 84 | */ |
||
| 85 | public function getCity() : ?City |
||
| 86 | { |
||
| 87 | return $this->municipality; |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @return \Talentify\ValueObject\Geography\Address\ByCountry\Br\State|null |
||
| 92 | */ |
||
| 93 | public function getRegion() : ?Region |
||
| 94 | { |
||
| 95 | return $this->state; |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @return \Talentify\ValueObject\Geography\Address\ByCountry\Br\State|null |
||
| 100 | */ |
||
| 101 | public function getState() : ?BrState |
||
| 102 | { |
||
| 103 | return $this->state; |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @return \Talentify\ValueObject\Geography\Address\ByCountry\Br\CEP|null |
||
| 108 | */ |
||
| 109 | public function getPostalCode() : ?PostalCode |
||
| 110 | { |
||
| 111 | return $this->postalCode; |
||
| 112 | } |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @return \Talentify\ValueObject\Geography\Address\ByCountry\Br\CEP|null |
||
| 116 | */ |
||
| 117 | public function getCep() : ? BrPostalCode |
||
| 118 | { |
||
| 119 | return $this->postalCode; |
||
| 120 | } |
||
| 121 | |||
| 122 | public function getCountry() : Country |
||
| 125 | } |
||
| 126 | |||
| 127 | public function equals(?ValueObject $object) : bool |
||
| 128 | { |
||
| 129 | if (!$object instanceof self) { |
||
| 130 | return false; |
||
| 131 | } |
||
| 132 | |||
| 158 | ) |
||
| 159 | ); |
||
| 160 | } |
||
| 161 | |||
| 162 | public function getAddress() : string |
||
| 185 | } |
||
| 186 | |||
| 187 | public function __toString() : string |
||
| 192 |