Track machine counters and maintenance with counter and time intervals

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-26 16:52:49 +02:00
co-authored by Claude Sonnet 5.5
parent aac579257a
commit 3e1c671949
53 changed files with 2636 additions and 6 deletions
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
namespace App\Modules\Machines\Domain\ValueObjects;
use App\Modules\Machines\Domain\Exceptions\InvalidReading;
/**
* A counter reading or a counter amount in thousandths of the counter's
* unit, typed as "20000", "20 000" or "12,5".
*/
final class Reading
{
/**
* @return int|null Null for an empty value.
*
* @throws InvalidReading
*/
public static function parse(string $value): ?int
{
$value = str_replace(',', '.', preg_replace('/[\s\x{00A0}\x{202F}]+/u', '', $value) ?? '');
if ($value === '') {
return null;
}
if (preg_match('/^(\d{1,12})(?:\.(\d{1,3}))?$/', $value, $matches) !== 1) {
throw new InvalidReading;
}
return (int) $matches[1] * 1000 + (int) str_pad($matches[2] ?? '', 3, '0');
}
}