Lines 0.00% 0 / 12
Methods 0.00% 0 / 4
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 __construct 0.00% 0 / 1 0.00% 0 / 1 2
 type 0.00% 0 / 1 0.00% 0 / 1 6
 summary 0.00% 0 / 2 0.00% 0 / 1 6
 boundsNote 0.00% 0 / 8 0.00% 0 / 1 72
9final readonly class FieldModel
10{
11    public function __construct(
12        public string $parameter,
13        public ServiceField $field,
14    ) {}
15
16    public function type(): PhpType
17    {
18        return $this->field->required ? $this->field->type : $this->field->type->nullable();
19    }
20
21    public function summary(): string
22    {
23        $parts = array_filter([$this->field->label, $this->field->description, $this->boundsNote()], static fn(?string $part): bool => $part !== null && $part !== '');
24
25        return implode('. ', array_map(static fn(string $part): string => rtrim($part, '.'), $parts));
26    }
27
28    private function boundsNote(): ?string
29    {
30        $min = $this->field->min;
31        $max = $this->field->max;
32        $unit = $this->field->unit === null ? '' : ' ' . $this->field->unit;
33
34        return match (true) {
35            $min !== null && $max !== null => \sprintf('%s to %s%s', $min, $max, $unit),
36            $min !== null => \sprintf('at least %s%s', $min, $unit),
37            $max !== null => \sprintf('at most %s%s', $max, $unit),
38            $unit !== '' => 'in' . $unit,
39            default => null,
40        };
41    }
42}