Lines 100.00% 16 / 16
Methods 100.00% 6 / 6
Classes 100.00% 1 / 1
Name Lines Methods CRAP
 __construct 100.00% 4 / 4 100.00% 1 / 1 4
 isLoopback 100.00% 1 / 1 100.00% 1 / 1 1
 toConnectableAddress 100.00% 1 / 1 100.00% 1 / 1 2
 resolveSocketAddress 100.00% 1 / 1 100.00% 1 / 1 1
 __toString 100.00% 1 / 1 100.00% 1 / 1 1
 [Stewart\Runtime\Config\ControlAddress] parse 100.00% 8 / 8 100.00% 1 / 1 3
9final readonly class TcpControlAddress extends ControlAddress
10{
11    private const array WILDCARD_HOSTS = ['0.0.0.0', '::', '[::]', '*'];
12
13    private const array LOOPBACK_HOSTS = ['127.0.0.1', '::1', '[::1]', 'localhost'];
14
15    /** @throws ConfigurationException */
16    public function __construct(
17        public string $host,
18        public int $port,
19    ) {
20        if ($host === '') {
21            throw ConfigurationException::valueInvalid((string) $this, 'a TCP control address with a host and a port');
22        }
23
24        if ($port < 1 || $port > 65535) {
25            throw ConfigurationException::valueInvalid((string) $this, 'a TCP control address with a port in 1-65535');
26        }
27    }
28
29    public function isLoopback(): bool
30    {
31        return \in_array($this->host, self::LOOPBACK_HOSTS, true);
32    }
33
34    public function toConnectableAddress(): self
35    {
36        return \in_array($this->host, self::WILDCARD_HOSTS, true) ? new self('127.0.0.1', $this->port) : $this;
37    }
38
39    public function resolveSocketAddress(ProjectRoot $projectRoot): string
40    {
41        return (string) $this;
42    }
43
44    public function __toString(): string
45    {
46        return \sprintf('tcp://%s:%d', $this->host, $this->port);
47    }
48}

Inherited from Stewart\Runtime\Config\ControlAddress

16    public static function parse(string $address): self
17    {
18        if (preg_match('~\Aunix://(.+)\z~', $address, $unix) === 1) {
19            return new UnixControlAddress($unix[1]);
20        }
21
22        if (preg_match('~\Atcp://(\[[0-9a-fA-F:.]+\]|[^:/\[\]]+):([0-9]{1,5})\z~', $address, $tcp) === 1) {
23            return new TcpControlAddress($tcp[1], (int) $tcp[2]);
24        }
25
26        throw ConfigurationException::valueInvalid(
27            $address,
28            'a control address; use unix://path, tcp://host:port or "off"',
29        );
30    }