Lines 100.00% 4 / 4
Methods 100.00% 1 / 1
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 4 / 4 100.00% 1 / 1 3
9final readonly class DeviceInfo
10{
11    private const string IDENTIFIER_PATTERN = '/\A[a-z][a-z0-9_]*\z/';
12
13    /** @throws ExposureException */
14    public function __construct(
15        public string $identifier,
16        public string $name,
17        public ?string $manufacturer = null,
18        public ?string $model = null,
19        public ?string $suggestedArea = null,
20    ) {
21        if (preg_match(self::IDENTIFIER_PATTERN, $identifier) !== 1) {
22            throw ExposureException::configInvalid(\sprintf('The device identifier "%s" must be lowercase letters, digits and "_", starting with a letter.', $identifier));
23        }
24
25        if ($name === '') {
26            throw ExposureException::configInvalid('The device name must not be empty.');
27        }
28    }
29}