refactor: clean up redundant readonly property modifiers and harmonize EntityId constructors
This commit is contained in:
parent
0c25d663f8
commit
59ceab8185
8 changed files with 15 additions and 9 deletions
|
|
@ -11,8 +11,10 @@ final readonly class ArcadiaEmployeeId extends EntityId
|
|||
private const string PATTERN = '/^\d{7,8}$/';
|
||||
|
||||
public function __construct(
|
||||
public readonly string $value
|
||||
string $value
|
||||
) {
|
||||
parent::__construct($value);
|
||||
|
||||
if (! preg_match(self::PATTERN, $value)) {
|
||||
throw new \DomainException(
|
||||
"Invalid value '{$value}' does not match pattern " . self::PATTERN
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ final readonly class EstablishmentCode
|
|||
private const string PATTERN = '/^[\dA-Z]{2,}$/';
|
||||
|
||||
public function __construct(
|
||||
public readonly string $value
|
||||
public string $value
|
||||
) {
|
||||
if (! preg_match(self::PATTERN, $value)) {
|
||||
throw new \DomainException(
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ final readonly class IncoCompositionId extends EntityId
|
|||
private const string PATTERN = '/^\d{1,}$/';
|
||||
|
||||
public function __construct(
|
||||
public readonly string $value
|
||||
string $value
|
||||
) {
|
||||
parent::__construct($value);
|
||||
|
||||
if (! preg_match(self::PATTERN, $value)) {
|
||||
throw new \DomainException(
|
||||
"Invalid value '{$value}' does not match pattern " . self::PATTERN
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ final readonly class IncoId extends EntityId
|
|||
private const string PATTERN = '/^\d{1,}$/';
|
||||
|
||||
public function __construct(
|
||||
public readonly string $value
|
||||
string $value
|
||||
) {
|
||||
parent::__construct($value);
|
||||
|
||||
if (! preg_match(self::PATTERN, $value)) {
|
||||
throw new \DomainException(
|
||||
"Invalid value '{$value}' does not match pattern " . self::PATTERN
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ final readonly class Nutriscore
|
|||
public const array VALID_GRADES = ['A', 'B', 'C', 'D', 'E'];
|
||||
|
||||
public function __construct(
|
||||
public readonly string $grade,
|
||||
public string $grade,
|
||||
) {
|
||||
if (! in_array($this->grade, self::VALID_GRADES, true)) {
|
||||
throw new \DomainException(
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ final readonly class ServiceId
|
|||
private const string PATTERN = '/^\d{1,}$/';
|
||||
|
||||
public function __construct(
|
||||
public readonly string $value
|
||||
public string $value
|
||||
) {
|
||||
if (! preg_match(self::PATTERN, $value)) {
|
||||
throw new \DomainException(
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ final readonly class SiteId
|
|||
private const string PATTERN = '/^[A-Z]{2,}$/';
|
||||
|
||||
public function __construct(
|
||||
public readonly string $value
|
||||
public string $value
|
||||
) {
|
||||
if (! preg_match(self::PATTERN, $value)) {
|
||||
throw new \DomainException(
|
||||
|
|
|
|||
|
|
@ -7,9 +7,9 @@ namespace Shared\DDD;
|
|||
abstract readonly class EntityId implements \Stringable, Equatable
|
||||
{
|
||||
public function __construct(
|
||||
public readonly string $value
|
||||
public string $value
|
||||
) {
|
||||
if (empty($value) || trim($value) === '') {
|
||||
if (trim($value) === '') {
|
||||
throw new \DomainException('EntityId value cannot be empty');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue