-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
namespace Booni3\DhlExpressRest\DTO; | ||
|
||
use Booni3\DhlExpressRest\AddressException; | ||
|
||
class Address | ||
{ | ||
protected $customer = []; | ||
|
@@ -15,6 +17,7 @@ public function __construct( | |
string $city, | ||
string $postcode, | ||
string $countrycode, | ||
string $typecode, | ||
string $company = '-', | ||
string $phone = '-', | ||
string $email = '[email protected]' | ||
|
@@ -34,6 +37,7 @@ public function __construct( | |
'fullName' => $name, | ||
'email' => $email, | ||
], | ||
'typeCode' => $this->validateTypeCode($typecode) | ||
]; | ||
} | ||
|
||
|
@@ -97,8 +101,21 @@ protected function registrationNumbers() | |
]; | ||
} | ||
|
||
public function getCityName() | ||
{ | ||
return $this->customer['postalAddress']['cityName']; | ||
} | ||
|
||
public function getCountryCode() | ||
{ | ||
return $this->customer['postalAddress']['countryCode']; | ||
} | ||
|
||
protected function validateTypeCode(string $typeCode){ | ||
if(! in_array($typeCode, ['business', 'direct_consumer'])){ | ||
throw AddressException::validationException('typeCode'); | ||
} | ||
|
||
return $typeCode; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
|
||
namespace Booni3\DhlExpressRest; | ||
|
||
|
||
class AddressException extends \Exception | ||
{ | ||
public static function validationException(string $field) | ||
{ | ||
throw new static("Validation Exception For Address: $field"); | ||
} | ||
} |