refactor: clean up redundant readonly property modifiers and harmonize EntityId constructors

This commit is contained in:
Jérémy Munsch 2026-08-17 09:42:21 +02:00
parent 0c25d663f8
commit 59ceab8185
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4
8 changed files with 15 additions and 9 deletions

View file

@ -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

View file

@ -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(

View file

@ -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

View file

@ -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

View file

@ -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(

View file

@ -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(

View file

@ -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(

View file

@ -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');
}
}