diff --git a/src/Domain/Models/Entities/Employee.php b/src/Domain/Models/Entities/Employee.php index 9885e4c..4a8b1bb 100644 --- a/src/Domain/Models/Entities/Employee.php +++ b/src/Domain/Models/Entities/Employee.php @@ -13,7 +13,7 @@ use Shared\DDD\Model\Entity; /** @implements Entity */ final readonly class Employee implements Entity { - public function __construct( + private function __construct( public ArcadiaEmployeeId $publicEmployeeNumber, public string $lastName, public string $firstName, @@ -33,4 +33,32 @@ final readonly class Employee implements Entity { return $this->publicEmployeeNumber; } + + public static function hydrate( + ArcadiaEmployeeId $publicEmployeeNumber, + string $lastName, + string $firstName, + \DateTimeInterface $startDate, + ?\DateTimeInterface $endDate, + ?\DateTimeInterface $plannedEndDate, + EstablishmentCode $establishment, + SiteId $site, + ServiceId $service, + \DateTimeInterface $createdAt, + ?\DateTimeInterface $updatedAt, + ): self { + return new self( + publicEmployeeNumber: $publicEmployeeNumber, + lastName: $lastName, + firstName: $firstName, + startDate: $startDate, + endDate: $endDate, + plannedEndDate: $plannedEndDate, + establishment: $establishment, + site: $site, + service: $service, + createdAt: $createdAt, + updatedAt: $updatedAt, + ); + } } diff --git a/src/Domain/Models/Entities/Inco/Composition/IncoComposition.php b/src/Domain/Models/Entities/Inco/Composition/IncoComposition.php index cf20064..112a743 100644 --- a/src/Domain/Models/Entities/Inco/Composition/IncoComposition.php +++ b/src/Domain/Models/Entities/Inco/Composition/IncoComposition.php @@ -25,7 +25,7 @@ use Shared\DDD\Model\Entity; /** @implements Entity */ final readonly class IncoComposition implements Entity { - public function __construct( + private function __construct( public IncoCompositionId $id, public IncoId $idInco, public Identification $identification, @@ -50,4 +50,42 @@ final readonly class IncoComposition implements Entity { return $this->id; } + + public static function hydrate( + IncoCompositionId $id, + IncoId $idInco, + Identification $identification, + Energy $energy, + ReferenceMacronutrients $referenceMacronutrients, + PortionMacronutrients $portionMacronutrients, + FreshProduceAndNuts $freshProduceAndNuts, + ReferenceIntakes $referenceIntakes, + NutriScore $nutriScore, + NutriScorePoints $nutriScorePoints, + Minerals $minerals, + Vitamins $vitamins, + CarbohydratesDetail $carbohydratesDetail, + FattyAcids $fattyAcids, + AminoAcids $aminoAcids, + SpecialCompounds $specialCompounds, + ): self { + return new self( + id: $id, + idInco: $idInco, + identification: $identification, + energy: $energy, + referenceMacronutrients: $referenceMacronutrients, + portionMacronutrients: $portionMacronutrients, + freshProduceAndNuts: $freshProduceAndNuts, + referenceIntakes: $referenceIntakes, + nutriScore: $nutriScore, + nutriScorePoints: $nutriScorePoints, + minerals: $minerals, + vitamins: $vitamins, + carbohydratesDetail: $carbohydratesDetail, + fattyAcids: $fattyAcids, + aminoAcids: $aminoAcids, + specialCompounds: $specialCompounds, + ); + } } diff --git a/src/Domain/Models/Entities/Inco/IncoSheet.php b/src/Domain/Models/Entities/Inco/IncoSheet.php index 906f397..a80a724 100644 --- a/src/Domain/Models/Entities/Inco/IncoSheet.php +++ b/src/Domain/Models/Entities/Inco/IncoSheet.php @@ -22,7 +22,7 @@ final readonly class IncoSheet implements Entity * @param array<\Domain\Models\ValueObjects\Inco\Allergen> $allergens * @param array<\Domain\Models\ValueObjects\Inco\Additive> $additives */ - public function __construct( + private function __construct( public IncoId $id, public string $name, public string $label, @@ -52,4 +52,56 @@ final readonly class IncoSheet implements Entity { return $this->id; } + + /** + * @param array<\Domain\Models\ValueObjects\Inco\Allergen> $allergens + * @param array<\Domain\Models\ValueObjects\Inco\Additive> $additives + */ + public static function hydrate( + IncoId $id, + string $name, + string $label, + string $description, + Allegations $allegations, + string $sellArguments, + string $preparationAdvices, + ?string $tips, + ?string $sellFamilly, + Ingredients $ingredients, + ?PortionAmount $portions, + array $allergens, + Brand $brand, + bool $isSeasonal, + ?IncoWeight $weight, + ?Nutriscore $nutriscore, + ?StorageCondition $storageCondition, + array $additives, + ?IncoCompositionId $compo, + ?\DateTimeInterface $createdAt, + ?\DateTimeInterface $updatedAt, + ): self { + return new self( + id: $id, + name: $name, + label: $label, + description: $description, + allegations: $allegations, + sellArguments: $sellArguments, + preparationAdvices: $preparationAdvices, + tips: $tips, + sellFamilly: $sellFamilly, + ingredients: $ingredients, + portions: $portions, + allergens: $allergens, + brand: $brand, + isSeasonal: $isSeasonal, + weight: $weight, + nutriscore: $nutriscore, + storageCondition: $storageCondition, + additives: $additives, + compo: $compo, + createdAt: $createdAt, + updatedAt: $updatedAt, + ); + } } diff --git a/src/Domain/Models/Entities/Inco/IncoShortSheet.php b/src/Domain/Models/Entities/Inco/IncoShortSheet.php index 89249b7..a0342bb 100644 --- a/src/Domain/Models/Entities/Inco/IncoShortSheet.php +++ b/src/Domain/Models/Entities/Inco/IncoShortSheet.php @@ -10,7 +10,7 @@ use Shared\DDD\Model\Entity; /** @implements Entity */ final readonly class IncoShortSheet implements Entity { - public function __construct( + private function __construct( public IncoId $id, public string $name, public string $label, @@ -24,4 +24,20 @@ final readonly class IncoShortSheet implements Entity { return $this->id; } + + public static function hydrate( + IncoId $id, + string $name, + string $label, + ?\DateTimeInterface $createdAt, + ?\DateTimeInterface $updatedAt, + ): self { + return new self( + id: $id, + name: $name, + label: $label, + createdAt: $createdAt, + updatedAt: $updatedAt, + ); + } } diff --git a/src/Infra/Adapters/Directories/EloquentEmployeeDirectory.php b/src/Infra/Adapters/Directories/EloquentEmployeeDirectory.php index 5ee2b7b..dc5293a 100644 --- a/src/Infra/Adapters/Directories/EloquentEmployeeDirectory.php +++ b/src/Infra/Adapters/Directories/EloquentEmployeeDirectory.php @@ -93,7 +93,7 @@ final class EloquentEmployeeDirectory implements EmployeeDirectory throw new \UnexpectedValueException('Employee created_at cannot be null.'); } - return new Employee( + return Employee::hydrate( publicEmployeeNumber: new ArcadiaEmployeeId((string) $employee->public_employee_number), lastName: (string) $employee->last_name, firstName: (string) $employee->first_name, diff --git a/src/Infra/Adapters/Directories/EloquentIncoCompositionDirectory.php b/src/Infra/Adapters/Directories/EloquentIncoCompositionDirectory.php index a1210e7..bb165af 100644 --- a/src/Infra/Adapters/Directories/EloquentIncoCompositionDirectory.php +++ b/src/Infra/Adapters/Directories/EloquentIncoCompositionDirectory.php @@ -60,7 +60,7 @@ final class EloquentIncoCompositionDirectory implements IncoCompositionDirectory private function toDomain(IncoCompoModel $model): IncoComposition { - return new IncoComposition( + return IncoComposition::hydrate( id: new IncoCompositionId((string) $model->id), idInco: new IncoId((string) $model->id_inco), identification: $this->identificationFrom($model), diff --git a/src/Infra/Adapters/Directories/EloquentIncoSheetDirectory.php b/src/Infra/Adapters/Directories/EloquentIncoSheetDirectory.php index 44ebd33..2516073 100644 --- a/src/Infra/Adapters/Directories/EloquentIncoSheetDirectory.php +++ b/src/Infra/Adapters/Directories/EloquentIncoSheetDirectory.php @@ -128,7 +128,7 @@ final class EloquentIncoSheetDirectory implements IncoSheetDirectory $compo = $model->compo_id !== null ? new IncoCompositionId((string) $model->compo_id) : null; - return new IncoSheet( + return IncoSheet::hydrate( id: new IncoId((string) $model->id), name: (string) $model->name, label: (string) $model->label, diff --git a/src/Infra/Adapters/Directories/EloquentIncoShortSheetDirectory.php b/src/Infra/Adapters/Directories/EloquentIncoShortSheetDirectory.php index d7096a3..5066928 100644 --- a/src/Infra/Adapters/Directories/EloquentIncoShortSheetDirectory.php +++ b/src/Infra/Adapters/Directories/EloquentIncoShortSheetDirectory.php @@ -121,7 +121,7 @@ final class EloquentIncoShortSheetDirectory implements IncoShortSheetDirectory $createdAt = is_string($rawCreatedAt) ? DatesHelper::parseDateTime($rawCreatedAt) : null; $updatedAt = is_string($rawUpdatedAt) ? DatesHelper::parseDateTime($rawUpdatedAt) : null; - return new IncoShortSheet( + return IncoShortSheet::hydrate( id: new IncoId($id), name: $name, label: $label, diff --git a/src/Shared/DDD/Exception/NotFoundException.php b/src/Shared/DDD/Exception/NotFoundException.php index 2420ad0..8c35080 100644 --- a/src/Shared/DDD/Exception/NotFoundException.php +++ b/src/Shared/DDD/Exception/NotFoundException.php @@ -4,6 +4,6 @@ declare(strict_types=1); namespace Shared\DDD\Exception; -class NotFoundException extends \RuntimeException +class NotFoundException extends \DomainException { } diff --git a/tests/Unit/Application/Arcadia/Usecase/Employees/FindAllEmployeesTest.php b/tests/Unit/Application/Arcadia/Usecase/Employees/FindAllEmployeesTest.php index 6bfa95d..530c89a 100644 --- a/tests/Unit/Application/Arcadia/Usecase/Employees/FindAllEmployeesTest.php +++ b/tests/Unit/Application/Arcadia/Usecase/Employees/FindAllEmployeesTest.php @@ -35,7 +35,7 @@ describe('FindAllEmployees Usecase Unit Tests', function (): void { it('executes successfully and returns paginated output DTO', function () use ($directory): void { // GIVEN $employeeId = new ArcadiaEmployeeId('01155902'); - $employee = new Employee( + $employee = Employee::hydrate( publicEmployeeNumber: $employeeId, lastName: 'DOE', firstName: 'John', diff --git a/tests/Unit/Application/Arcadia/Usecase/Employees/FindEmployeeTest.php b/tests/Unit/Application/Arcadia/Usecase/Employees/FindEmployeeTest.php index c050303..1296257 100644 --- a/tests/Unit/Application/Arcadia/Usecase/Employees/FindEmployeeTest.php +++ b/tests/Unit/Application/Arcadia/Usecase/Employees/FindEmployeeTest.php @@ -31,7 +31,7 @@ describe('FindEmployee Usecase Unit Tests', function (): void { it('executes successfully and returns Output when employee exists', function () use ($directory): void { // GIVEN $employeeId = new ArcadiaEmployeeId('01155902'); - $employee = new Employee( + $employee = Employee::hydrate( publicEmployeeNumber: $employeeId, lastName: 'DOE', firstName: 'John', diff --git a/tests/Unit/Application/Arcadia/Usecase/IncoCompositions/FindIncoCompositionTest.php b/tests/Unit/Application/Arcadia/Usecase/IncoCompositions/FindIncoCompositionTest.php index 29b9478..0dad43b 100644 --- a/tests/Unit/Application/Arcadia/Usecase/IncoCompositions/FindIncoCompositionTest.php +++ b/tests/Unit/Application/Arcadia/Usecase/IncoCompositions/FindIncoCompositionTest.php @@ -72,7 +72,7 @@ describe('FindIncoComposition Usecase Unit Tests', function (): void { $amino = new AminoAcids('0', '0', '0'); $special = new SpecialCompounds('0', '0', '0', '0'); - return new IncoComposition( + return IncoComposition::hydrate( id: $compoId, idInco: $incoId, identification: $identification, diff --git a/tests/Unit/Application/Arcadia/Usecase/Incosheets/FindAllIncoSheetsDtoTest.php b/tests/Unit/Application/Arcadia/Usecase/Incosheets/FindAllIncoSheetsDtoTest.php index 89db2d8..cfdfc9a 100644 --- a/tests/Unit/Application/Arcadia/Usecase/Incosheets/FindAllIncoSheetsDtoTest.php +++ b/tests/Unit/Application/Arcadia/Usecase/Incosheets/FindAllIncoSheetsDtoTest.php @@ -42,7 +42,7 @@ describe('FindAllIncoSheets DTOs Instantiation & Logic', function (): void { it('creates PaginatedIncoSheet and PaginatedShortIncoSheet from domain entity and instantiates Output DTO', function (): void { // GIVEN $incoId = new IncoId('12345'); - $incoSheet = new IncoSheet( + $incoSheet = IncoSheet::hydrate( id: $incoId, name: 'Poulet Rôti 1kg', label: 'Poulet Rôti Classe A', @@ -66,7 +66,7 @@ describe('FindAllIncoSheets DTOs Instantiation & Logic', function (): void { updatedAt: null, ); - $shortSheet = new IncoShortSheet( + $shortSheet = IncoShortSheet::hydrate( id: $incoId, name: 'Poulet Rôti 1kg', label: 'Poulet Rôti Classe A', diff --git a/tests/Unit/Application/Arcadia/Usecase/Incosheets/FindAllIncoSheetsTest.php b/tests/Unit/Application/Arcadia/Usecase/Incosheets/FindAllIncoSheetsTest.php index abbab84..ba89db3 100644 --- a/tests/Unit/Application/Arcadia/Usecase/Incosheets/FindAllIncoSheetsTest.php +++ b/tests/Unit/Application/Arcadia/Usecase/Incosheets/FindAllIncoSheetsTest.php @@ -40,7 +40,7 @@ describe('FindAllIncoSheets Usecase Unit Tests', function (): void { it('executes successfully and returns paginated output DTO', function () use ($directory, $shortDirectory): void { // GIVEN $incoId = new IncoId('12345'); - $incoSheet = new IncoSheet( + $incoSheet = IncoSheet::hydrate( id: $incoId, name: 'Poulet Rôti 1kg', label: 'Poulet Rôti Classe A', diff --git a/tests/Unit/Application/Arcadia/Usecase/Incosheets/FindIncoSheetTest.php b/tests/Unit/Application/Arcadia/Usecase/Incosheets/FindIncoSheetTest.php index 4c92bc4..0c20b86 100644 --- a/tests/Unit/Application/Arcadia/Usecase/Incosheets/FindIncoSheetTest.php +++ b/tests/Unit/Application/Arcadia/Usecase/Incosheets/FindIncoSheetTest.php @@ -31,7 +31,7 @@ describe('FindIncoSheet Usecase Unit Tests', function (): void { it('executes successfully and returns Output when inco sheet exists', function () use ($directory): void { // GIVEN $incoId = new IncoId('12345'); - $incoSheet = new IncoSheet( + $incoSheet = IncoSheet::hydrate( id: $incoId, name: 'Poulet Rôti 1kg', label: 'Poulet Rôti Classe A', diff --git a/tests/Unit/Application/Arcadia/Usecase/Incosheets/SearchIncoSheetsTest.php b/tests/Unit/Application/Arcadia/Usecase/Incosheets/SearchIncoSheetsTest.php index 86b0f27..9b46e3a 100644 --- a/tests/Unit/Application/Arcadia/Usecase/Incosheets/SearchIncoSheetsTest.php +++ b/tests/Unit/Application/Arcadia/Usecase/Incosheets/SearchIncoSheetsTest.php @@ -39,7 +39,7 @@ describe('SearchIncoSheets Usecase Unit Tests', function (): void { it('searches full inco sheets matching query and brands', function () use ($directory, $shortDirectory): void { // GIVEN - $incoSheet = new IncoSheet( + $incoSheet = IncoSheet::hydrate( id: new IncoId('12345'), name: 'Poulet Rôti 1kg', label: 'Poulet Rôti Classe A', @@ -83,7 +83,7 @@ describe('SearchIncoSheets Usecase Unit Tests', function (): void { it('searches short inco sheets when short option is true', function () use ($directory, $shortDirectory): void { // GIVEN - $shortSheet = new IncoShortSheet( + $shortSheet = IncoShortSheet::hydrate( id: new IncoId('12345'), name: 'Poulet Rôti 1kg', label: 'Poulet Rôti Classe A', diff --git a/tests/Unit/Domain/Entities/EmployeeTest.php b/tests/Unit/Domain/Entities/EmployeeTest.php index 62ec51d..1b45608 100644 --- a/tests/Unit/Domain/Entities/EmployeeTest.php +++ b/tests/Unit/Domain/Entities/EmployeeTest.php @@ -19,7 +19,7 @@ describe('Employee Entity', function (): void { $now = new \DateTimeImmutable(); // WHEN - $employee = new Employee( + $employee = Employee::hydrate( publicEmployeeNumber: $id, lastName: 'Dupont', firstName: 'Jean', diff --git a/tests/Unit/Domain/Entities/IncoCompositionEntityTest.php b/tests/Unit/Domain/Entities/IncoCompositionEntityTest.php index 4fbfc28..7fad3d1 100644 --- a/tests/Unit/Domain/Entities/IncoCompositionEntityTest.php +++ b/tests/Unit/Domain/Entities/IncoCompositionEntityTest.php @@ -201,7 +201,7 @@ describe('IncoComposition Domain Entity Unit Tests', function (): void { $specialCompounds = new SpecialCompounds('0', '0', '0', '0'); // WHEN - $compo = new IncoComposition( + $compo = IncoComposition::hydrate( id: $id, idInco: $idInco, identification: $identification, diff --git a/tests/Unit/Domain/Entities/IncoSheetEntityTest.php b/tests/Unit/Domain/Entities/IncoSheetEntityTest.php index 9c809fe..4a9e2b8 100644 --- a/tests/Unit/Domain/Entities/IncoSheetEntityTest.php +++ b/tests/Unit/Domain/Entities/IncoSheetEntityTest.php @@ -22,7 +22,7 @@ describe('IncoSheet Domain Entity Unit Tests', function (): void { $brand = new Brand('M01', 'Le Gaulois'); // WHEN - $sheet = new IncoSheet( + $sheet = IncoSheet::hydrate( id: $id, name: 'Poulet Rôti 1kg', label: 'Poulet Rôti Classe A', diff --git a/tests/Unit/Infra/Adapters/Directories/InMemoryEmployeeDirectoryTest.php b/tests/Unit/Infra/Adapters/Directories/InMemoryEmployeeDirectoryTest.php index d84a3fb..381cfab 100644 --- a/tests/Unit/Infra/Adapters/Directories/InMemoryEmployeeDirectoryTest.php +++ b/tests/Unit/Infra/Adapters/Directories/InMemoryEmployeeDirectoryTest.php @@ -22,7 +22,7 @@ describe('InMemoryEmployeeDirectory Unit Tests', function (): void { // GIVEN $directory = new InMemoryEmployeeDirectory(); $employeeId = new ArcadiaEmployeeId('01155902'); - $employee = new Employee( + $employee = Employee::hydrate( publicEmployeeNumber: $employeeId, lastName: 'DOE', firstName: 'John', @@ -51,7 +51,7 @@ describe('InMemoryEmployeeDirectory Unit Tests', function (): void { // GIVEN $directory = new InMemoryEmployeeDirectory(); - $emp1 = new Employee( + $emp1 = Employee::hydrate( publicEmployeeNumber: new ArcadiaEmployeeId('00000001'), lastName: 'ALICE', firstName: 'A', @@ -65,7 +65,7 @@ describe('InMemoryEmployeeDirectory Unit Tests', function (): void { updatedAt: null, ); - $emp2 = new Employee( + $emp2 = Employee::hydrate( publicEmployeeNumber: new ArcadiaEmployeeId('00000002'), lastName: 'BOB', firstName: 'B', @@ -98,7 +98,7 @@ describe('InMemoryEmployeeDirectory Unit Tests', function (): void { // GIVEN $directory = new InMemoryEmployeeDirectory(); - $emp1 = new Employee( + $emp1 = Employee::hydrate( publicEmployeeNumber: new ArcadiaEmployeeId('00000001'), lastName: 'ALICE', firstName: 'A', @@ -112,7 +112,7 @@ describe('InMemoryEmployeeDirectory Unit Tests', function (): void { updatedAt: null, ); - $emp2 = new Employee( + $emp2 = Employee::hydrate( publicEmployeeNumber: new ArcadiaEmployeeId('00000002'), lastName: 'BOB', firstName: 'B', @@ -126,7 +126,7 @@ describe('InMemoryEmployeeDirectory Unit Tests', function (): void { updatedAt: new \DateTimeImmutable('2024-02-01'), ); - $emp3 = new Employee( + $emp3 = Employee::hydrate( publicEmployeeNumber: new ArcadiaEmployeeId('00000003'), lastName: 'CHARLIE', firstName: 'C', @@ -160,7 +160,7 @@ describe('InMemoryEmployeeDirectory Unit Tests', function (): void { // GIVEN $directory = new InMemoryEmployeeDirectory(); $employeeId = new ArcadiaEmployeeId('01155902'); - $employee = new Employee( + $employee = Employee::hydrate( publicEmployeeNumber: $employeeId, lastName: 'DOE', firstName: 'John', diff --git a/tests/Unit/Infra/Adapters/Directories/InMemoryIncoCompositionDirectoryTest.php b/tests/Unit/Infra/Adapters/Directories/InMemoryIncoCompositionDirectoryTest.php index f2af456..8e8fb76 100644 --- a/tests/Unit/Infra/Adapters/Directories/InMemoryIncoCompositionDirectoryTest.php +++ b/tests/Unit/Infra/Adapters/Directories/InMemoryIncoCompositionDirectoryTest.php @@ -53,7 +53,7 @@ describe('InMemoryIncoCompositionDirectory Unit Tests', function (): void { $amino = new AminoAcids('0', '0', '0'); $special = new SpecialCompounds('0', '0', '0', '0'); - return new IncoComposition( + return IncoComposition::hydrate( id: $compoId, idInco: $incoId, identification: $identification, diff --git a/tests/Unit/Infra/Adapters/Directories/InMemoryIncoSheetDirectoryTest.php b/tests/Unit/Infra/Adapters/Directories/InMemoryIncoSheetDirectoryTest.php index b9f9598..62e07e4 100644 --- a/tests/Unit/Infra/Adapters/Directories/InMemoryIncoSheetDirectoryTest.php +++ b/tests/Unit/Infra/Adapters/Directories/InMemoryIncoSheetDirectoryTest.php @@ -21,7 +21,7 @@ covers(InMemoryIncoSheetDirectory::class); describe('InMemoryIncoSheetDirectory Unit Tests', function (): void { function createSheet(string $idStr, string $brandCode, string $brandLabel): IncoSheet { - return new IncoSheet( + return IncoSheet::hydrate( id: new IncoId($idStr), name: 'Sheet ' . $idStr, label: 'Label ' . $idStr, diff --git a/tests/Unit/Infra/Adapters/Directories/InMemoryIncoShortSheetDirectoryTest.php b/tests/Unit/Infra/Adapters/Directories/InMemoryIncoShortSheetDirectoryTest.php index 6e731d5..c7b7991 100644 --- a/tests/Unit/Infra/Adapters/Directories/InMemoryIncoShortSheetDirectoryTest.php +++ b/tests/Unit/Infra/Adapters/Directories/InMemoryIncoShortSheetDirectoryTest.php @@ -18,7 +18,7 @@ covers(InMemoryIncoShortSheetDirectory::class); describe('InMemoryIncoShortSheetDirectory Unit Tests', function (): void { function createShortSheet(string $idStr): IncoShortSheet { - return new IncoShortSheet( + return IncoShortSheet::hydrate( id: new IncoId($idStr), name: 'Sheet ' . $idStr, label: 'Label ' . $idStr,