Lines 83.33% 5 / 6
Functions and Methods 50.00% 1 / 2
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
ActionConfig 83.33% 5 / 6 50.00% 1 / 2 4.07 0.00% 0 / 1
 __construct 100.00% 5 / 5 100.00% 1 / 1 3
 getPlatform 0.00% 0 / 1 0.00% 0 / 1 2
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Contracts\Exposure\Action;
6
7use Stewart\Contracts\Exception\ExposureException;
8use Stewart\Contracts\Exposure\ExposedPlatform;
9use Stewart\Contracts\Exposure\ExposureConfig;
10use Stewart\Contracts\Wire\ListOf;
11
12final readonly class ActionConfig implements ExposureConfig
13{
14    /**
15     * @param list<ActionField> $fields
16     * @throws ExposureException
17     */
18    public function __construct(
19        public ?string $name = null,
20        public ?string $description = null,
21        #[ListOf(ActionField::class)]
22        public array $fields = [],
23    ) {
24        if ($name === '') {
25            throw ExposureException::configInvalid('The action name must not be empty; leave it null to use the key.');
26        }
27
28        $names = array_map(static fn(ActionField $field): string => $field->name, $fields);
29
30        if (\count(array_unique($names)) !== \count($names)) {
31            throw ExposureException::configInvalid('The action field names must be distinct.');
32        }
33    }
34
35    public function getPlatform(): ExposedPlatform
36    {
37        return ExposedPlatform::Action;
38    }
39}