Test Setup Failed
Push — master ( 99e44e...109dee )
by Pablo
01:48
created

CountryCode::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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