Lines 95.65% 22 / 23
Methods 85.71% 6 / 7
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 __construct 50.00% 1 / 2 0.00% 0 / 1 2.50
 resolveSocketPath 100.00% 9 / 9 100.00% 1 / 1 2
 isLoopback 100.00% 1 / 1 100.00% 1 / 1 1
 toConnectableAddress 100.00% 1 / 1 100.00% 1 / 1 1
 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
10final readonly class UnixControlAddress extends ControlAddress
11{
12    // Linux sun_path is 108 bytes, less a terminating NUL and a temp suffix.
13    private const int MAX_SOCKET_PATH_BYTES = 100;
14
15    /** @throws ConfigurationException */
16    public function __construct(public string $path)
17    {
18        if ($path === '') {
19            throw ConfigurationException::valueInvalid('unix://', 'a unix control address with a path');
20        }
21    }
22
23    /** @throws ConfigurationException */
24    public function resolveSocketPath(ProjectRoot $projectRoot): string
25    {
26        $absolutePath = $projectRoot->resolvePath($this->path);
27
28        if (\strlen($absolutePath) > self::MAX_SOCKET_PATH_BYTES) {
29            throw ConfigurationException::valueInvalid((string) $this, \sprintf(
30                'a unix control address; the resolved path %s is %d bytes, the limit is %d',
31                $absolutePath,
32                \strlen($absolutePath),
33                self::MAX_SOCKET_PATH_BYTES,
34            ));
35        }
36
37        return $absolutePath;
38    }
39
40    public function isLoopback(): bool
41    {
42        return true;
43    }
44
45    public function toConnectableAddress(): self
46    {
47        return $this;
48    }
49
50    /** @throws ConfigurationException */
51    public function resolveSocketAddress(ProjectRoot $projectRoot): UnixAddress
52    {
53        return new UnixAddress($this->resolveSocketPath($projectRoot));
54    }
55
56    public function __toString(): string
57    {
58        return 'unix://' . $this->path;
59    }
60}

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    }