-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from jirik1h/master
Add AddressesForServices to export package method
- Loading branch information
Showing
5 changed files
with
427 additions
and
18 deletions.
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
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Salamek\PplMyApi\Enum; | ||
|
||
class AddressForService | ||
{ | ||
public const RETURN_ADDRESS_NORMAL_PACKAGE = 'BP'; | ||
public const RETURN_ADDRESS_RETURN_PACKAGE = 'RETD'; | ||
public const RETURN_ADDRESS_CONNECT_PACKAGE = 'RETC'; | ||
|
||
/** @var array */ | ||
public static $list = [ | ||
self::RETURN_ADDRESS_NORMAL_PACKAGE, | ||
self::RETURN_ADDRESS_RETURN_PACKAGE, | ||
self::RETURN_ADDRESS_CONNECT_PACKAGE, | ||
]; | ||
} |
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,247 @@ | ||
<?php | ||
|
||
namespace Salamek\PplMyApi\Model; | ||
|
||
use Salamek\PplMyApi\Enum\Country; | ||
use Salamek\PplMyApi\Exception\WrongDataException; | ||
use Salamek\PplMyApi\Validators\MaxLengthValidator; | ||
use Salamek\PplMyApi\Enum\AddressForService as AddressForServiceEnum; | ||
|
||
class AddressForService implements IAddressForService | ||
{ | ||
/** @var string */ | ||
private $city; | ||
|
||
/** @var null|string */ | ||
private $contact = null; | ||
|
||
/** @var null|string */ | ||
private $country = null; | ||
|
||
/** @var null|string */ | ||
private $email = null; | ||
|
||
/** @var string */ | ||
private $name; | ||
|
||
/** @var null|string */ | ||
private $name2 = null; | ||
|
||
/** @var null|string */ | ||
private $phone = null; | ||
|
||
/** @var string */ | ||
private $street; | ||
|
||
/** @var string */ | ||
private $zipCode; | ||
|
||
/** @var IFlag[] */ | ||
private $flags; | ||
|
||
/** @var string */ | ||
private $serviceAddressType; | ||
|
||
/** | ||
* @param iFlag[] $flags | ||
* @throws WrongDataException | ||
*/ | ||
public function __construct( | ||
string $serviceAddressType, | ||
string $city, | ||
string $name, | ||
string $street, | ||
string $zipCode, | ||
string $email = null, | ||
string $phone = null, | ||
string $contact = null, | ||
string $country = Country::CZ, | ||
string $name2 = null, | ||
array $flags = [] | ||
) { | ||
$this->setServiceAddressType($serviceAddressType); | ||
$this->setCity($city); | ||
$this->setName($name); | ||
$this->setStreet($street); | ||
$this->setZipCode($zipCode); | ||
$this->setEmail($email); | ||
$this->setPhone($phone); | ||
$this->setContact($contact); | ||
$this->setCountry($country); | ||
$this->setName2($name2); | ||
$this->setFlags($flags); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setServiceAddressType(string $serviceAddressType) | ||
{ | ||
if (!in_array($serviceAddressType, AddressForServiceEnum::$list)) { | ||
throw new WrongDataException( | ||
sprintf('$packageProductType has wrong value, only %s are allowed', implode(', ', AddressForServiceEnum::$list)) | ||
); | ||
} | ||
$this->serviceAddressType = $serviceAddressType; | ||
} | ||
|
||
public function setCity(string $city) | ||
{ | ||
MaxLengthValidator::validate($city, 50); | ||
$this->city = $city; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setContact(string $contact) | ||
{ | ||
if (!is_null($contact)) { | ||
MaxLengthValidator::validate($contact, 30); | ||
} | ||
|
||
$this->contact = $contact; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setCountry(string $country) | ||
{ | ||
if (!in_array($country, Country::$list)) { | ||
throw new WrongDataException(sprintf('Country Code %s is not supported, use one of %s', $country, implode(', ', Country::$list))); | ||
} | ||
$this->country = $country; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setEmail(string $email) | ||
{ | ||
if (!is_null($email)) { | ||
MaxLengthValidator::validate($email, 100); | ||
|
||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { | ||
throw new WrongDataException('$email have invalid value'); | ||
} | ||
} | ||
|
||
|
||
$this->email = $email; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setName(string $name) | ||
{ | ||
MaxLengthValidator::validate($name, 250); | ||
$this->name = $name; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setName2(string $name2) | ||
{ | ||
if (!is_null($name2)) { | ||
MaxLengthValidator::validate($name2, 250); | ||
} | ||
|
||
$this->name2 = $name2; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setPhone(string $phone) | ||
{ | ||
if (!is_null($phone)) { | ||
MaxLengthValidator::validate($phone, 30); | ||
} | ||
|
||
$this->phone = $phone; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setStreet(string $street) | ||
{ | ||
MaxLengthValidator::validate($street, 30); | ||
$this->street = $street; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function setZipCode(string $zipCode) | ||
{ | ||
MaxLengthValidator::validate($zipCode, 10); | ||
$this->zipCode = $zipCode; | ||
} | ||
|
||
/** | ||
* @param IFlag[] $flags | ||
*/ | ||
public function setFlags(array $flags) | ||
{ | ||
$this->flags = $flags; | ||
} | ||
|
||
public function getCity(): string | ||
{ | ||
return $this->city; | ||
} | ||
|
||
public function getContact(): ?string | ||
{ | ||
return $this->contact; | ||
} | ||
|
||
public function getCountry(): ?string | ||
{ | ||
return $this->country; | ||
} | ||
|
||
public function getEmail(): ?string | ||
{ | ||
return $this->email; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getName2(): ?string | ||
{ | ||
return $this->name2; | ||
} | ||
|
||
public function getPhone(): ?string | ||
{ | ||
return $this->phone; | ||
} | ||
|
||
public function getStreet(): string | ||
{ | ||
return $this->street; | ||
} | ||
|
||
public function getZipCode(): string | ||
{ | ||
return $this->zipCode; | ||
} | ||
|
||
public function getFlags(): array | ||
{ | ||
return $this->flags; | ||
} | ||
|
||
public function getServiceAddressType(): string | ||
{ | ||
return $this->serviceAddressType; | ||
} | ||
} |
Oops, something went wrong.