-
Notifications
You must be signed in to change notification settings - Fork 0
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
36 changed files
with
524 additions
and
627 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,9 @@ | ||
<?php | ||
|
||
namespace ThePay\ApiClient\ValueObject; | ||
declare(strict_types=1); | ||
|
||
use InvalidArgumentException; | ||
namespace ThePay\ApiClient\ValueObject; | ||
|
||
/** | ||
* @extends BaseValueObject<int> | ||
*/ | ||
final class Amount extends BaseValueObject | ||
class Amount extends IntValue | ||
{ | ||
/** | ||
* Amount constructor. | ||
* | ||
* @param int $value | ||
*/ | ||
public function __construct($value) | ||
{ | ||
if ( ! is_int($value)) { | ||
throw new InvalidArgumentException('Value has to be an integer.'); | ||
} | ||
|
||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
return (string) $this->value; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getValue() | ||
{ | ||
return $this->value; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,37 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ThePay\ApiClient\ValueObject; | ||
|
||
/** | ||
* @extends BaseValueObject<string> | ||
*/ | ||
final class CountryCode extends BaseValueObject | ||
class CountryCode extends NonEmptyString | ||
{ | ||
/** | ||
* @param string $value | ||
*/ | ||
public function __construct($value) | ||
protected static function filter($value) | ||
{ | ||
if ( ! is_string($value) || ! preg_match('/[A-Z]{2}/', $value)) { | ||
throw new \InvalidArgumentException('Value `' . $value . '` is not valid ISO 3166-1 (alpha-2) country code'); | ||
} | ||
|
||
$this->value = $value; | ||
} | ||
$nonEmptyString = parent::filter($value); | ||
$countryCodeCandidate = trim($nonEmptyString); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
return $this->value; | ||
} | ||
if (preg_match('/^[A-Z]{2}$/', $countryCodeCandidate) !== 1) { | ||
throw self::invalidValue('ISO 3166-1 (alpha-2) country code', $nonEmptyString); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getValue() | ||
{ | ||
return $this->value; | ||
return $countryCodeCandidate; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,43 +1,20 @@ | ||
<?php | ||
|
||
namespace ThePay\ApiClient\ValueObject; | ||
declare(strict_types=1); | ||
|
||
use InvalidArgumentException; | ||
namespace ThePay\ApiClient\ValueObject; | ||
|
||
/** | ||
* @extends BaseValueObject<string> | ||
*/ | ||
final class CurrencyCode extends BaseValueObject | ||
class CurrencyCode extends NonEmptyString | ||
{ | ||
/** | ||
* CurrencyCode constructor. | ||
* | ||
* @param string $value | ||
*/ | ||
public function __construct($value) | ||
protected static function filter($value) | ||
{ | ||
$value = trim($value); | ||
$nonEmptyString = parent::filter($value); | ||
$currencyCodeCandidate = trim($nonEmptyString); | ||
|
||
if (strlen($value) !== 3) { | ||
throw new InvalidArgumentException('Value `' . $value . '` is not valid ISO 4217 currency code'); | ||
if (preg_match('/^[A-Z]{3}$/', $currencyCodeCandidate) !== 1) { | ||
throw self::invalidValue('ISO 4217 currency code', $nonEmptyString); | ||
} | ||
|
||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
return (string) $this->value; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getValue() | ||
{ | ||
return $this->value; | ||
return $currencyCodeCandidate; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,45 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ThePay\ApiClient\ValueObject; | ||
|
||
/** | ||
* @extends BaseValueObject<string> | ||
* @note all subclasses should be final / you can not inherit from enum | ||
*/ | ||
abstract class EnumValueObject extends BaseValueObject | ||
abstract class EnumValueObject extends StringValue | ||
{ | ||
/** | ||
* @param string $value | ||
* @return string[] | ||
*/ | ||
public function __construct($value) | ||
{ | ||
if ( ! in_array($value, static::getOptions(), true)) { | ||
throw new \InvalidArgumentException(sprintf('%s in not valid value', $value)); | ||
} | ||
abstract public static function cases(): array; | ||
|
||
$this->value = $value; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString() | ||
protected static function filter($value) | ||
{ | ||
return (string) $this->value; | ||
} | ||
$caseCandidate = parent::filter($value); | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getValue() | ||
{ | ||
return $this->value; | ||
} | ||
if ( ! in_array($caseCandidate, static::cases(), true)) { | ||
throw self::invalidValue('case', $caseCandidate); | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public static function getOptions() | ||
{ | ||
return []; | ||
return $caseCandidate; | ||
} | ||
} |
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 |
---|---|---|
@@ -1,43 +1,21 @@ | ||
<?php | ||
|
||
namespace ThePay\ApiClient\ValueObject; | ||
declare(strict_types=1); | ||
|
||
use InvalidArgumentException; | ||
namespace ThePay\ApiClient\ValueObject; | ||
|
||
/** | ||
* @extends BaseValueObject<string> | ||
*/ | ||
final class Identifier extends BaseValueObject | ||
class Identifier extends NonEmptyString | ||
{ | ||
/** | ||
* Uid constructor. | ||
* | ||
* @param string $value | ||
*/ | ||
public function __construct($value) | ||
public const STRLEN_MAX = 100; | ||
|
||
protected static function filter($value) | ||
{ | ||
$value = trim($value); | ||
$identifierCandidate = trim(parent::filter($value)); | ||
|
||
if (strlen($value) > 100) { | ||
throw new InvalidArgumentException('Value\'s length has to be up to 100 characters'); | ||
if (strlen($identifierCandidate) > self::STRLEN_MAX) { | ||
throw self::invalidValue(sprintf('up to %d characters', self::STRLEN_MAX), $identifierCandidate); | ||
} | ||
|
||
$this->value = (string) $value; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function __toString() | ||
{ | ||
return $this->value; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getValue() | ||
{ | ||
return $this->value; | ||
return $identifierCandidate; | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ThePay\ApiClient\ValueObject; | ||
|
||
/** | ||
* @extends BaseValueObject<int> | ||
*/ | ||
class IntValue extends BaseValueObject | ||
{ | ||
public function __toString() | ||
{ | ||
return (string) $this->value; | ||
} | ||
|
||
protected static function filter($value) | ||
{ | ||
$intCandidate = filter_var($value, FILTER_VALIDATE_INT); | ||
|
||
if ($intCandidate === false) { | ||
throw self::invalidValue('int'); | ||
} | ||
|
||
return $intCandidate; | ||
} | ||
} |
Oops, something went wrong.