address vo changes

This commit is contained in:
Yuri Kuznetsov
2021-05-08 20:09:17 +03:00
parent a15daa87c5
commit 3f8d272eee
2 changed files with 21 additions and 23 deletions
+14 -16
View File
@@ -46,6 +46,20 @@ class Address
private $postalCode = null;
public function __construct(
?string $country = null,
?string $state = null,
?string $city = null,
?string $street = null,
?string $postalCode = null
) {
$this->country = $country;
$this->state = $state;
$this->city = $city;
$this->street = $street;
$this->postalCode = $postalCode;
}
/**
* Whether has a street.
*/
@@ -191,22 +205,6 @@ class Address
return $newAddress;
}
/**
* Create a RAW data.
*/
public static function fromRaw(array $raw): self
{
$obj = new self();
$obj->street = $raw['street'] ?? null;
$obj->city = $raw['city'] ?? null;
$obj->country = $raw['country'] ?? null;
$obj->state = $raw['state'] ?? null;
$obj->postalCode = $raw['postalCode'] ?? null;
return $obj;
}
/**
* Create an empty address.
*/
@@ -94,12 +94,12 @@ class AddressBuilder
public function build(): Address
{
return Address::fromRaw([
'street' => $this->street,
'city' => $this->city,
'country' => $this->country,
'state' => $this->state,
'postalCode' => $this->postalCode,
]);
return new Address(
$this->country,
$this->state,
$this->city,
$this->street,
$this->postalCode
);
}
}