fix: 🐛 new structures and fix linters

This commit is contained in:
K Muller 2026-10-02 11:33:03 +02:00 • committed by Corentin Huet
parent a9147e27c7
commit 871ceade05
12 changed files with 16 additions and 142 deletions

View file

@ -7,7 +7,6 @@ namespace Domain\Models\ValueObjects\Campaign;
use Domain\Models\ValueObjects\Coupon\CouponQuantity;
use Domain\Models\ValueObjects\PrintRules;
use Domain\Models\ValueObjects\ProcessingCode;
use Domain\Models\ValueObjects\WarningThresholdQuantity;
use Shared\Enums\Country;
final readonly class CampaignCoupon
@ -16,7 +15,6 @@ final readonly class CampaignCoupon
public ProcessingCode $processingCode,
public CouponQuantity $quantity,
public Country $availableIn,
public ?WarningThresholdQuantity $warningThresholdQuantity = null,
public ?PrintRules $printRules = null,
) {
}

View file

@ -13,17 +13,13 @@ use Domain\Models\ValueObjects\MoneyAmount;
use Domain\Models\ValueObjects\Period;
use Domain\Models\ValueObjects\PrintRules;
use Domain\Models\ValueObjects\ProcessingCode;
use Domain\Models\ValueObjects\WarningThresholdQuantity;
use Shared\Enums\Country;
final readonly class RequestedCoupon
{
private const int DEFAULT_WARNING_THRESHOLD_QUANTITY = 100;
private const int MIN_FACE_VALUE_IN_CENTS = 1;
private const int MAX_FACE_VALUE_IN_CENTS = 300;
public WarningThresholdQuantity $warningThresholdQuantity;
/**
* @param array<CouponValidityInformation> $couponValidityInformation
* @param array<IncoCode> $products
@ -39,7 +35,6 @@ final readonly class RequestedCoupon
public array $products = [],
public ?PrintRules $printRules = null,
public ?GS1 $gs1 = null,
?WarningThresholdQuantity $warningThresholdQuantity = null,
) {
$money = $this->moneyAmount->value;
@ -63,8 +58,6 @@ final readonly class RequestedCoupon
if ($this->gs1 instanceof GS1 && !$this->hasValidityInformationFor(Country::BENELUX)) {
throw new \DomainException('A GS1 coupon requires validity information for Benelux.');
}
$this->warningThresholdQuantity = $warningThresholdQuantity ?? new WarningThresholdQuantity(self::DEFAULT_WARNING_THRESHOLD_QUANTITY);
}
private function hasValidityInformationFor(Country $country): bool

View file

@ -1,16 +0,0 @@
<?php
declare(strict_types=1);
namespace Domain\Models\ValueObjects;
final readonly class WarningThresholdQuantity
{
public function __construct(
public int $value,
) {
if ($this->value < 0) {
throw new \DomainException('Warning threshold quantity cannot be negative.');
}
}
}

View file

@ -25,7 +25,6 @@ use Domain\Models\ValueObjects\PrintRules;
use Domain\Models\ValueObjects\ProcessingCode;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCoupon;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCouponQuantity;
use Domain\Models\ValueObjects\WarningThresholdQuantity;
use Domain\Ports\Repositories\BrandRepository;
use Domain\Ports\Repositories\CampaignRequestRepository;
use Shared\Enums\Country;
@ -52,8 +51,7 @@ beforeEach(function (): void {
new CouponValidityInformation('Lorem ipsum dolor sit amet consectetur adipiscing elit.', Country::FRANCE),
],
products: [new IncoCode(35784), new IncoCode(15522)],
printRules: new PrintRules(maxPerCustomer: 3),
warningThresholdQuantity: new WarningThresholdQuantity(10),
printRules: new PrintRules(maxPerCustomer: 3)
),
);
});

View file

@ -35,7 +35,6 @@ use Domain\Models\ValueObjects\PrintRules;
use Domain\Models\ValueObjects\ProcessingCode;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCoupon;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCouponQuantity;
use Domain\Models\ValueObjects\WarningThresholdQuantity;
use Domain\Ports\Repositories\BrandRepository;
use Domain\Ports\Repositories\CampaignRequestRepository;
use Shared\DDD\UseCases\Input as BaseInput;
@ -62,8 +61,7 @@ describe('find campaign request use case', function (): void {
],
[new IncoCode(35784), new IncoCode(15522)],
new PrintRules(maxPerCustomer: 3),
new GS1('01234567890128', BarcodeFormat::EAN13),
new WarningThresholdQuantity(10)
new GS1('01234567890128', BarcodeFormat::EAN13)
);
});

View file

@ -28,7 +28,6 @@ use Domain\Models\ValueObjects\PrintRules;
use Domain\Models\ValueObjects\ProcessingCode;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCoupon;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCouponQuantity;
use Domain\Models\ValueObjects\WarningThresholdQuantity;
use Domain\Ports\Repositories\CampaignRequestRepository;
use Shared\Enums\Country;
use Shared\Enums\Currency;
@ -54,8 +53,7 @@ describe('list campaigns request use case', function (): void {
],
[new IncoCode(35784), new IncoCode(15522)],
new PrintRules(maxPerCustomer: 3),
new GS1('01234567890128', BarcodeFormat::EAN13),
new WarningThresholdQuantity(10)
new GS1('01234567890128', BarcodeFormat::EAN13)
);
$this->couponB = new RequestedCoupon(
@ -71,8 +69,7 @@ describe('list campaigns request use case', function (): void {
],
[new IncoCode(24514), new IncoCode(46259)],
new PrintRules(maxPerCustomer: 3),
new GS1('01234567890128', BarcodeFormat::EAN13),
new WarningThresholdQuantity(10)
new GS1('01234567890128', BarcodeFormat::EAN13)
);
});

View file

@ -31,7 +31,6 @@ use Domain\Models\ValueObjects\PrintRules;
use Domain\Models\ValueObjects\ProcessingCode;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCoupon;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCouponQuantity;
use Domain\Models\ValueObjects\WarningThresholdQuantity;
use Domain\Ports\Repositories\CampaignRequestRepository;
use Shared\Enums\Country;
use Shared\Enums\Currency;
@ -55,8 +54,7 @@ describe('reject campaign request use case', function (): void {
],
[new IncoCode(35784), new IncoCode(15522)],
new PrintRules(maxPerCustomer: 3),
new GS1('01234567890128', BarcodeFormat::EAN13),
new WarningThresholdQuantity(10)
new GS1('01234567890128', BarcodeFormat::EAN13)
);
});

View file

@ -26,7 +26,6 @@ use Domain\Models\ValueObjects\PrintRules;
use Domain\Models\ValueObjects\ProcessingCode;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCoupon;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCouponQuantity;
use Domain\Models\ValueObjects\WarningThresholdQuantity;
use Ramsey\Uuid\Uuid;
use Shared\Enums\Country;
use Shared\Enums\Currency;
@ -50,8 +49,7 @@ describe('campaign request', function (): void {
],
[new IncoCode(35784), new IncoCode(15522)],
new PrintRules(maxPerCustomer: 3),
new GS1('01234567890128', BarcodeFormat::EAN13),
new WarningThresholdQuantity(10)
new GS1('01234567890128', BarcodeFormat::EAN13)
);
$this->code = new BrandCode('AAA01');
$this->name = new CampaignName('Campaign A');

View file

@ -16,7 +16,6 @@ use Domain\Models\ValueObjects\Campaign\CampaignName;
use Domain\Models\ValueObjects\Coupon\CouponQuantity;
use Domain\Models\ValueObjects\PrintRules;
use Domain\Models\ValueObjects\ProcessingCode;
use Domain\Models\ValueObjects\WarningThresholdQuantity;
use Ramsey\Uuid\Uuid;
covers(Campaign::class);
@ -32,7 +31,6 @@ describe('campaign', function (): void {
new ProcessingCode('PC1'),
new CouponQuantity(100),
Country::FRANCE,
new WarningThresholdQuantity(100),
new PrintRules(maxPerCustomer: 3)
)
];

View file

@ -8,7 +8,6 @@ use Domain\Models\ValueObjects\Campaign\CampaignCoupon;
use Domain\Models\ValueObjects\Coupon\CouponQuantity;
use Domain\Models\ValueObjects\PrintRules;
use Domain\Models\ValueObjects\ProcessingCode;
use Domain\Models\ValueObjects\WarningThresholdQuantity;
use Shared\Enums\Country;
covers(CampaignCoupon::class);
@ -18,7 +17,6 @@ describe('campaign coupon', function (): void {
$this->processingCode = new ProcessingCode('PC1');
$this->quantity = new CouponQuantity(10);
$this->availableIn = Country::FRANCE;
$this->warningThresholdQuantity = new WarningThresholdQuantity(100);
$this->printRules = new PrintRules(maxPerCustomer: 3);
});
@ -28,7 +26,6 @@ describe('campaign coupon', function (): void {
$this->processingCode,
$this->quantity,
$this->availableIn,
$this->warningThresholdQuantity,
$this->printRules
);
@ -36,7 +33,6 @@ describe('campaign coupon', function (): void {
expect($campaignCoupon->processingCode)->toBe($this->processingCode)
->and($campaignCoupon->quantity)->toBe($this->quantity)
->and($campaignCoupon->availableIn)->toBe($this->availableIn)
->and($campaignCoupon->warningThresholdQuantity)->toBe($this->warningThresholdQuantity)
->and($campaignCoupon->printRules)->toBe($this->printRules);
});
@ -62,14 +58,12 @@ describe('campaign coupon', function (): void {
processingCode: $this->processingCode,
quantity: $this->quantity,
availableIn: $this->availableIn,
warningThresholdQuantity: $this->warningThresholdQuantity
);
// THEN
expect($campaignCoupon->processingCode)->toBe($this->processingCode)
->and($campaignCoupon->quantity)->toBe($this->quantity)
->and($campaignCoupon->availableIn)->toBe($this->availableIn)
->and($campaignCoupon->warningThresholdQuantity)->toBe($this->warningThresholdQuantity);
->and($campaignCoupon->availableIn)->toBe($this->availableIn);
});
it('creates a valid campaign coupon whitout warning threshold quantity and print rules', function (): void {

View file

@ -18,7 +18,6 @@ use Domain\Models\ValueObjects\PrintRules;
use Domain\Models\ValueObjects\ProcessingCode;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCoupon;
use Domain\Models\ValueObjects\RequestedCoupon\RequestedCouponQuantity;
use Domain\Models\ValueObjects\WarningThresholdQuantity;
use Shared\Enums\Country;
use Shared\Enums\Currency;
use Shared\ValueObjects\Money;
@ -48,7 +47,6 @@ describe('requested coupon', function (): void {
$this->products = [new IncoCode(35784), new IncoCode(15522)];
$this->printRules = new PrintRules(maxPerCustomer: 3);
$this->gs1 = new GS1('01234567890128', BarcodeFormat::EAN13);
$this->warningThresholdQuantity = new WarningThresholdQuantity(10);
});
afterEach(function (): void {
@ -68,7 +66,6 @@ describe('requested coupon', function (): void {
$this->products,
$this->printRules,
$this->gs1,
$this->warningThresholdQuantity
);
// THEN
@ -81,8 +78,7 @@ describe('requested coupon', function (): void {
->and($coupon->couponValidityInformation)->toBe($this->couponValidityInformation)
->and($coupon->products)->toBe($this->products)
->and($coupon->printRules)->toBe($this->printRules)
->and($coupon->gs1)->toBe($this->gs1)
->and($coupon->warningThresholdQuantity)->toBe($this->warningThresholdQuantity);
->and($coupon->gs1)->toBe($this->gs1);
});
it('hydrates a requested coupon without products', function (): void {
@ -96,15 +92,13 @@ describe('requested coupon', function (): void {
couponValidity: $this->couponValidity,
couponValidityInformation: $this->couponValidityInformation,
printRules: $this->printRules,
gs1: $this->gs1,
warningThresholdQuantity: $this->warningThresholdQuantity
gs1: $this->gs1
);
// THEN
expect($coupon->products)->toBe([])
->and($coupon->printRules)->toBe($this->printRules)
->and($coupon->gs1)->toBe($this->gs1)
->and($coupon->warningThresholdQuantity)->toBe($this->warningThresholdQuantity);
->and($coupon->gs1)->toBe($this->gs1);
});
it('hydrates a requested coupon without print rules', function (): void {
@ -118,15 +112,13 @@ describe('requested coupon', function (): void {
couponValidity: $this->couponValidity,
couponValidityInformation: $this->couponValidityInformation,
products: $this->products,
gs1: $this->gs1,
warningThresholdQuantity: $this->warningThresholdQuantity
gs1: $this->gs1
);
// THEN
expect($coupon->printRules)->toBeNull()
->and($coupon->products)->toBe($this->products)
->and($coupon->gs1)->toBe($this->gs1)
->and($coupon->warningThresholdQuantity)->toBe($this->warningThresholdQuantity);
->and($coupon->gs1)->toBe($this->gs1);
});
it('hydrates a requested coupon without gs1', function (): void {
@ -140,37 +132,13 @@ describe('requested coupon', function (): void {
couponValidity: $this->couponValidity,
couponValidityInformation: $this->couponValidityInformation,
products: $this->products,
printRules: $this->printRules,
warningThresholdQuantity: $this->warningThresholdQuantity
printRules: $this->printRules
);
// THEN
expect($coupon->gs1)->toBeNull()
->and($coupon->products)->toBe($this->products)
->and($coupon->printRules)->toBe($this->printRules)
->and($coupon->warningThresholdQuantity)->toBe($this->warningThresholdQuantity);
});
it('defaults the warning threshold quantity to 100 when not provided', function (): void {
// GIVEN / WHEN
$coupon = new RequestedCoupon(
name: $this->name,
quantity: $this->quantity,
diffusion: $this->diffusion,
moneyAmount: $this->moneyAmount,
processingCode: $this->processingCode,
couponValidity: $this->couponValidity,
couponValidityInformation: $this->couponValidityInformation,
products: $this->products,
printRules: $this->printRules,
gs1: $this->gs1,
);
// THEN
expect($coupon->warningThresholdQuantity)->toEqual(new WarningThresholdQuantity(100))
->and($coupon->products)->toBe($this->products)
->and($coupon->printRules)->toBe($this->printRules)
->and($coupon->gs1)->toBe($this->gs1);
->and($coupon->printRules)->toBe($this->printRules);
});
it('hydrates a requested coupon with only required fields', function (): void {
@ -188,8 +156,7 @@ describe('requested coupon', function (): void {
// THEN
expect($coupon->products)->toBe([])
->and($coupon->printRules)->toBeNull()
->and($coupon->gs1)->toBeNull()
->and($coupon->warningThresholdQuantity)->toEqual(new WarningThresholdQuantity(100));
->and($coupon->gs1)->toBeNull();
});
it('throws when there is no validity information for france', function (): void {
@ -217,8 +184,7 @@ describe('requested coupon', function (): void {
['Not a CouponValidityInformation'],
$this->products,
$this->printRules,
$this->gs1,
$this->warningThresholdQuantity
$this->gs1
))->toThrow(\DomainException::class, 'Coupon validity information must be CouponValidityInformation instances.');
});

View file

@ -1,48 +0,0 @@
<?php
declare(strict_types=1);
namespace Tests\Unit\Domain\Models\ValueObjects;
use Domain\Models\ValueObjects\WarningThresholdQuantity;
covers(WarningThresholdQuantity::class);
describe('warning threshold quantity', function (): void {
beforeEach(function (): void {
$this->value = 10;
$this->zeroValue = 0;
$this->negativeValue = -1;
});
it('creates a valid warning threshold quantity', function (): void {
// GIVEN / WHEN
$warningThresholdQuantity = new WarningThresholdQuantity(
$this->value
);
// THEN
expect($warningThresholdQuantity)->toBeInstanceOf(WarningThresholdQuantity::class)
->and($warningThresholdQuantity->value)->toBe($this->value);
});
it('accepts a zero value, meaning no warning', function (): void {
// GIVEN / WHEN
$warningThresholdQuantity = new WarningThresholdQuantity(
$this->zeroValue
);
// THEN
expect($warningThresholdQuantity->value)->toBe($this->zeroValue);
});
it('rejects a negative value', function (): void {
// GIVEN / WHEN
$action = fn (): WarningThresholdQuantity => new WarningThresholdQuantity(
$this->negativeValue
);
// THEN
expect($action)->toThrow(\DomainException::class, 'Warning threshold quantity cannot be negative.');
});
});