Lines 66.66% 2 / 3
Functions and Methods 50.00% 1 / 2
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
StorePrefix 66.66% 2 / 3 50.00% 1 / 2 3.33 0.00% 0 / 1
 __construct 100.00% 2 / 2 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\Store;
6
7use Stewart\Store\Exception\StoreSetupError;
8use Stewart\Store\Exception\StoreSetupException;
9use Stringable;
10
11final readonly class StorePrefix implements Stringable
12{
13    /** @throws StoreSetupException */
14    public function __construct(public string $value)
15    {
16        if (preg_match('/\A[A-Za-z0-9][A-Za-z0-9._-]{0,63}\z/', $value) !== 1) {
17            throw StoreSetupException::createForReason(StoreSetupError::PrefixInvalid, prefix: $value);
18        }
19    }
20
21    public function __toString(): string
22    {
23        return $this->value;
24    }
25}