Lines 80.00% 4 / 5
Functions and Methods 50.00% 1 / 2
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
ClassNamespace 80.00% 4 / 5 50.00% 1 / 2 3.07 0.00% 0 / 1
 __construct 100.00% 4 / 4 100.00% 1 / 1 2
 __toString 0.00% 0 / 1 0.00% 0 / 1 2
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Config;
6
7use Stewart\Runtime\Exception\ConfigurationException;
8use Stringable;
9
10final readonly class ClassNamespace implements Stringable
11{
12    public string $value;
13
14    /** @throws ConfigurationException */
15    public function __construct(string $value)
16    {
17        $namespace = trim($value, '\\');
18
19        if (preg_match('/\A[A-Za-z_][A-Za-z0-9_]*(\\\\[A-Za-z_][A-Za-z0-9_]*)*\z/', $namespace) !== 1) {
20            throw ConfigurationException::valueInvalid($value, 'a PHP namespace such as "App\Generated"');
21        }
22
23        $this->value = $namespace;
24    }
25
26    public function __toString(): string
27    {
28        return $this->value;
29    }
30}