ValidatedUserId   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 25
ccs 10
cts 10
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A asStr() 0 13 2
1
<?php
2
3
namespace Raigu\XRoad\SoapEnvelope;
4
5
use PHPUnit\Runner\Exception;
6
7
/**
8
 * I am validated user id.
9
 *
10
 * I will throw exception if I am invalid.
11
 */
12
final class ValidatedUserId
13
{
14
    /**
15
     * @var string
16
     */
17
    private $userId;
18
19 2
    public function asStr(): string
20
    {
21 2
        $countryCode = substr($this->userId, 0, 2);
22 2
        if (preg_match('/^[A-Z]{2}$/', $countryCode) !== 1) {
23 1
            throw new Exception(
24 1
                sprintf(
25 1
                    'Invalid country code prefix in userId. Must be two-letter ISO country code. Actual: %s',
26 1
                    $countryCode
27
                )
28
            );
29
        }
30
31 1
        return $this->userId;
32
    }
33
34 2
    public function __construct(string $userId)
35
    {
36 2
        $this->userId = $userId;
37 2
    }
38
}
39