CountryCode::guard()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
ccs 5
cts 5
cp 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpValueObjects\Geography;
6
7
use PhpValueObjects\AbstractValueObject;
8
use Symfony\Component\Intl\Countries;
9
use Symfony\Component\Intl\Exception\MissingResourceException;
10
11
abstract class CountryCode extends AbstractValueObject
12
{
13 18
    public function __construct(string $value)
14
    {
15 18
        parent::__construct($value);
16 12
    }
17
18 18
    protected function guard($value): void
19
    {
20
        try {
21 18
            Countries::getName($value);
22 6
        } catch (MissingResourceException $e) {
23 6
            $this->throwException($value);
24
        }
25 12
    }
26
}
27