From 591ebf9fe20758b3eb0b2f4834eefad50ed2dae0 Mon Sep 17 00:00:00 2001 From: Corentin Huet Date: Wed, 23 Sep 2026 17:33:02 +0200 Subject: [PATCH] fix: :bug: resolve linter errors and tests --- src/Domain/Models/Entities/Campaign.php | 12 ++++++-- src/Domain/Models/Entities/Stock.php | 3 +- src/Domain/Models/Entities/Tag.php | 1 + .../ValueObjects/Campaign/CampaignCoupon.php | 5 ++-- .../Domain/Models/Entities/CampaignTest.php | 28 ++++--------------- .../Campaign/CampaignCouponTest.php | 17 +++++------ 6 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/Domain/Models/Entities/Campaign.php b/src/Domain/Models/Entities/Campaign.php index 48fdbf1..7ed5804 100644 --- a/src/Domain/Models/Entities/Campaign.php +++ b/src/Domain/Models/Entities/Campaign.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace Domain\Models\Entities; + use Domain\Enums\Country; use Domain\Models\Entities\Tag; use Domain\Models\ValueObjects\Brand\BrandCode; @@ -26,7 +27,7 @@ final readonly class Campaign implements AggregateRoot, HasTimestampIdentifier public bool $publication, public bool $printAllAtOnce, public Country $availableIn, - /** @var CampaignCoupon[] */ + /** @var array $coupons */ public array $coupons, public BrandCode $brand, public ?\DateTimeInterface $updatedAt = null, @@ -48,6 +49,9 @@ final readonly class Campaign implements AggregateRoot, HasTimestampIdentifier return $this->updatedAt; } + /** + * @param array $coupons + */ public static function create( CampaignCode $code, Tag $tag, @@ -55,7 +59,7 @@ final readonly class Campaign implements AggregateRoot, HasTimestampIdentifier bool $publication, bool $printAllAtOnce, Country $availableIn, - /** @var CampaignCoupon[] */ + /** @var array $coupons */ array $coupons, BrandCode $brand, ?\DateTimeInterface $updatedAt = null, @@ -74,6 +78,9 @@ final readonly class Campaign implements AggregateRoot, HasTimestampIdentifier ); } + /** + * @param array $coupons + */ public static function hydrate( CampaignId $id, CampaignCode $code, @@ -82,7 +89,6 @@ final readonly class Campaign implements AggregateRoot, HasTimestampIdentifier bool $publication, bool $printAllAtOnce, Country $availableIn, - /** @var CampaignCoupon[] */ array $coupons, BrandCode $brand, ?\DateTimeInterface $updatedAt = null, diff --git a/src/Domain/Models/Entities/Stock.php b/src/Domain/Models/Entities/Stock.php index 4d707dc..69693f1 100644 --- a/src/Domain/Models/Entities/Stock.php +++ b/src/Domain/Models/Entities/Stock.php @@ -25,7 +25,8 @@ final readonly class Stock implements AggregateRoot, HasTimestampIdentifier /** @var array $stockAdjustment */ public array $stockAdjustment, public ?\DateTimeInterface $updatedAt = null, - ) {} + ) { + } public function id(): StockId { diff --git a/src/Domain/Models/Entities/Tag.php b/src/Domain/Models/Entities/Tag.php index 449c8df..bb8e084 100644 --- a/src/Domain/Models/Entities/Tag.php +++ b/src/Domain/Models/Entities/Tag.php @@ -3,6 +3,7 @@ declare(strict_types=1); namespace Domain\Models\Entities; + use Domain\Models\ValueObjects\Tag\TagId; use Domain\Models\ValueObjects\Tag\TagName; use Shared\DDD\Models\AggregateRoot; diff --git a/src/Domain/Models/ValueObjects/Campaign/CampaignCoupon.php b/src/Domain/Models/ValueObjects/Campaign/CampaignCoupon.php index ced1d7f..2e7ca71 100644 --- a/src/Domain/Models/ValueObjects/Campaign/CampaignCoupon.php +++ b/src/Domain/Models/ValueObjects/Campaign/CampaignCoupon.php @@ -6,14 +6,15 @@ namespace Domain\Models\ValueObjects\Campaign; use Domain\Models\ValueObjects\PrintRules; use Domain\Models\ValueObjects\ProcessingCode; +use Domain\Models\ValueObjects\Stock\StockId; final readonly class CampaignCoupon { public function __construct( public ProcessingCode $code, public StockId $qty, - public ?PrintRules $printRules, - public int $warningThresholdQty + public int $warningThresholdQty, + public ?PrintRules $printRules = null, ) { if ($this->warningThresholdQty <= 0) { throw new \DomainException('Campaign Coupon warningThresholdQty must be positive.'); diff --git a/tests/Unit/Domain/Models/Entities/CampaignTest.php b/tests/Unit/Domain/Models/Entities/CampaignTest.php index 500b649..f2c0f92 100644 --- a/tests/Unit/Domain/Models/Entities/CampaignTest.php +++ b/tests/Unit/Domain/Models/Entities/CampaignTest.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Tests\Unit\Domain\Models\Entities; use Carbon\CarbonImmutable; -use Domain\Enums\BarcodeFormat; use Domain\Enums\Country; use Domain\Models\Entities\Campaign; use Domain\Models\Entities\Tag; @@ -14,26 +13,12 @@ use Domain\Models\ValueObjects\Campaign\CampaignCode; use Domain\Models\ValueObjects\Campaign\CampaignCoupon; use Domain\Models\ValueObjects\Campaign\CampaignId; use Domain\Models\ValueObjects\Campaign\CampaignName; -use Domain\Models\ValueObjects\Coupon\CouponAvailabilityCalendar; -use Domain\Models\ValueObjects\Coupon\CouponDiffusion; -use Domain\Models\ValueObjects\Coupon\CouponId; -use Domain\Models\ValueObjects\Coupon\CouponLegalInformation; -use Domain\Models\ValueObjects\Coupon\CouponProduct; -use Domain\Models\ValueObjects\Coupon\CouponValidity; -use Domain\Models\ValueObjects\CouponName; -use Domain\Models\ValueObjects\CouponPicture; -use Domain\Models\ValueObjects\CouponProductName; -use Domain\Models\ValueObjects\GS1; -use Domain\Models\ValueObjects\MoneyAmount; -use Domain\Models\ValueObjects\PicturePath; use Domain\Models\ValueObjects\PrintRules; use Domain\Models\ValueObjects\ProcessingCode; +use Domain\Models\ValueObjects\Stock\StockId; use Domain\Models\ValueObjects\Tag\TagId; use Domain\Models\ValueObjects\Tag\TagName; use Ramsey\Uuid\Uuid; -use Shared\Enums\Currency; -use Shared\ValueObjects\DateTime; -use Shared\ValueObjects\Money; covers(Campaign::class); @@ -57,7 +42,7 @@ describe('campaign', function (): void { $publication = \boolval(0); $printAllAtOnce = \boolval(1); $availableIn = Country::FR; - $coupons = [new CampaignCoupon(new ProcessingCode('PC1'), new StockId(1), new PrintRules(maxPerCustomer: 3), 100)]; + $coupons = [new CampaignCoupon(new ProcessingCode('PC1'), StockId::generate(), 100, new PrintRules(maxPerCustomer: 3))]; $brand = new BrandCode('AAA01'); // WHEN @@ -95,7 +80,7 @@ describe('campaign', function (): void { $publication = \boolval(0); $printAllAtOnce = \boolval(1); $availableIn = Country::FR; - $coupons = [new CampaignCoupon(new ProcessingCode('PC1'), new StockId(1), new PrintRules(maxPerCustomer: 3), 100)]; + $coupons = [new CampaignCoupon(new ProcessingCode('PC1'), StockId::generate(), 100, new PrintRules(maxPerCustomer: 3))]; $brand = new BrandCode('AAA01'); $updatedAt = new \DateTimeImmutable('2026-09-22 10:00:00', new \DateTimeZone('UTC')); @@ -125,7 +110,7 @@ describe('campaign', function (): void { $publication = \boolval(0); $printAllAtOnce = \boolval(1); $availableIn = Country::FR; - $coupons = [new CampaignCoupon(new ProcessingCode('PC1'), new StockId(1), new PrintRules(maxPerCustomer: 3), 100)]; + $coupons = [new CampaignCoupon(new ProcessingCode('PC1'), StockId::generate(), 100, new PrintRules(maxPerCustomer: 3))]; $brand = new BrandCode('AAA01'); // WHEN @@ -161,7 +146,7 @@ describe('campaign', function (): void { $publication = \boolval(0); $printAllAtOnce = \boolval(1); $availableIn = Country::FR; - $coupons = [new CampaignCoupon(new ProcessingCode('PC1'), new StockId(1), new PrintRules(maxPerCustomer: 3), 100)]; + $coupons = [new CampaignCoupon(new ProcessingCode('PC1'), StockId::generate(), 100, new PrintRules(maxPerCustomer: 3))]; $brand = new BrandCode('AAA01'); // WHEN @@ -202,8 +187,7 @@ describe('campaign', function (): void { \boolval(0), \boolval(1), Country::FR, - new GS1('110101010', BarcodeFormat::EAN13), - [new CampaignCoupon(new ProcessingCode('PC1'), new StockId(1), new PrintRules(maxPerCustomer: 3), 100)], + [new CampaignCoupon(new ProcessingCode('PC1'), StockId::generate(), 100, new PrintRules(maxPerCustomer: 3))], new BrandCode('AAA01') ); diff --git a/tests/Unit/Domain/Models/ValueObjects/Campaign/CampaignCouponTest.php b/tests/Unit/Domain/Models/ValueObjects/Campaign/CampaignCouponTest.php index 1be0701..9d1b6ba 100644 --- a/tests/Unit/Domain/Models/ValueObjects/Campaign/CampaignCouponTest.php +++ b/tests/Unit/Domain/Models/ValueObjects/Campaign/CampaignCouponTest.php @@ -7,6 +7,7 @@ namespace Tests\Unit\Domain\Models\ValueObjects\Campaign; use Domain\Models\ValueObjects\Campaign\CampaignCoupon; use Domain\Models\ValueObjects\PrintRules; use Domain\Models\ValueObjects\ProcessingCode; +use Domain\Models\ValueObjects\Stock\StockId; covers(CampaignCoupon::class); @@ -14,12 +15,12 @@ describe('campaign coupon', function (): void { it('creates a valid campaign coupon', function (): void { // GIVEN $code = new ProcessingCode('PC1'); - $qty = new StockId(); + $qty = StockId::generate(); $printRules = new PrintRules(maxPerCustomer: 3); $warningThresholdQty = 100; // WHEN - $campaignCoupon = new CampaignCoupon(code: $code, qty: $qty, printRules: $printRules, warningThresholdQty: $warningThresholdQty); + $campaignCoupon = new CampaignCoupon($code, $qty, $warningThresholdQty, $printRules); // THEN expect($campaignCoupon->code)->toBe($code) @@ -31,11 +32,11 @@ describe('campaign coupon', function (): void { it('creates a valid campaign coupon whitout print rules', function (): void { // GIVEN $code = new ProcessingCode('PC1'); - $qty = new StockId(); + $qty = StockId::generate(); $warningThresholdQty = 100; // WHEN - $campaignCoupon = new CampaignCoupon(code: $code, qty: $qty, warningThresholdQty: $warningThresholdQty); + $campaignCoupon = new CampaignCoupon($code, $qty, $warningThresholdQty); // THEN expect($campaignCoupon->code)->toBe($code) @@ -46,21 +47,21 @@ describe('campaign coupon', function (): void { it('rejects invalid campaign coupon', function (): void { // GIVEN $code = new ProcessingCode('PC1'); - $qty = new StockId(); + $qty = StockId::generate(); $printRules = new PrintRules(maxPerCustomer: 3); $warningThresholdQty = -100; // GIVEN / THEN - expect(fn (): CampaignCoupon => new CampaignCoupon(code: $code, qty: $qty, printRules: $printRules, warningThresholdQty: $warningThresholdQty))->toThrow(\DomainException::class); + expect(fn (): CampaignCoupon => new CampaignCoupon($code, $qty, $warningThresholdQty, $printRules))->toThrow(\DomainException::class); }); it('rejects invalid campaign coupon whitout print rules', function (): void { // GIVEN $code = new ProcessingCode('PC1'); - $qty = new StockId(); + $qty = StockId::generate(); $warningThresholdQty = -100; // GIVEN / THEN - expect(fn (): CampaignCoupon => new CampaignCoupon(code: $code, qty: $qty, warningThresholdQty: $warningThresholdQty))->toThrow(\DomainException::class); + expect(fn (): CampaignCoupon => new CampaignCoupon($code, $qty, $warningThresholdQty))->toThrow(\DomainException::class); }); });