37 lines
951 B
PHP
37 lines
951 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\Baselines\SnapshotRendering;
|
|
|
|
use InvalidArgumentException;
|
|
|
|
final readonly class RenderedAttribute
|
|
{
|
|
public function __construct(
|
|
public string $label,
|
|
public string $value,
|
|
public string $priority = 'primary',
|
|
) {
|
|
if (trim($this->label) === '') {
|
|
throw new InvalidArgumentException('RenderedAttribute label must be a non-empty string.');
|
|
}
|
|
|
|
if (! in_array($this->priority, ['primary', 'secondary'], true)) {
|
|
throw new InvalidArgumentException('RenderedAttribute priority must be either "primary" or "secondary".');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array{label: string, value: string, priority: string}
|
|
*/
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'label' => $this->label,
|
|
'value' => $this->value,
|
|
'priority' => $this->priority,
|
|
];
|
|
}
|
|
}
|