Files
2026-11-26 16:43:55 +02:00

37 lines
845 B
PHP

<?php
declare(strict_types=1);
namespace App\Modules\Machines\Domain\ValueObjects;
use App\Modules\Machines\Domain\Enums\CounterUnit;
use App\Modules\Machines\Domain\Exceptions\InvalidCounter;
/**
* A counter of a machine (laskuri, spec 19.5) by which maintenance needs
* are measured, e.g. prints or printed area. $id is null for a new one.
*/
final readonly class MachineCounter
{
public const int MAX_LENGTH = 100;
public string $name;
/**
* @throws InvalidCounter
*/
public function __construct(
public ?int $id,
string $name,
public CounterUnit $unit,
) {
$name = trim(preg_replace('/\s+/u', ' ', $name) ?? $name);
if ($name === '' || mb_strlen($name) > self::MAX_LENGTH) {
throw new InvalidCounter;
}
$this->name = $name;
}
}