Lines 83.33% 5 / 6
Functions and Methods 66.66% 2 / 3
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
HttpAdminConfig 83.33% 5 / 6 66.66% 2 / 3 3.04 0.00% 0 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 fromSection 100.00% 4 / 4 100.00% 1 / 1 1
 requireToken 0.00% 0 / 1 0.00% 0 / 1 2
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Config;
6
7use SensitiveParameter;
8use Stewart\Runtime\Exception\ConfigurationError;
9use Stewart\Runtime\Exception\ConfigurationException;
10
11final readonly class HttpAdminConfig
12{
13    public function __construct(
14        public ?HttpListenAddress $listen,
15        #[SensitiveParameter]
16        public ?string $token,
17    ) {}
18
19    /** @throws ConfigurationException */
20    public static function fromSection(#[SensitiveParameter] ConfigSection $admin): self
21    {
22        return new self(
23            listen: $admin->findSwitchableValue('listen', HttpListenAddress::parse(...)),
24            token: $admin->findSwitchableValue('token', strval(...)),
25        );
26    }
27
28    /** @throws ConfigurationException */
29    public function requireToken(): string
30    {
31        return $this->token ?? throw ConfigurationException::createForReason(ConfigurationError::AdminTokenMissing);
32    }
33}