ldc-cocotte/domain/Enums/TaxRate.php
2026-10-27 09:58:12 +01:00

48 lines
914 B
PHP

<?php
declare(strict_types=1);
namespace Domain\Enums;
use Domain\Services\PricingService;
use Money\Money;
use Shared\Enums\BaseEnum;
enum TaxRate: int
{
/** @use \Shared\Enums\BaseEnum<int> */
use BaseEnum;
case TVA_20 = 1;
case TVA_5_5 = 2;
/**
* Optional labels definition
*
* @phpstan-ignore-next-line
*/
private const LABELS = [
self::TVA_20->name => 'TVA 20%',
self::TVA_5_5->name => 'TVA 5.5%',
];
public function percent(): float
{
return match ($this) {
self::TVA_20 => 20.0,
self::TVA_5_5 => 5.5,
};
}
public function rate(): float
{
return $this->percent() / 100;
}
public function applyTo(Money $price): Money
{
$multiplier = (string) (1 + $this->rate());
return $price->multiply($multiplier, PricingService::ROUNDING);
}
}