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

CountryCode   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 3
dl 0
loc 19
rs 10
c 0
b 0
f 0
ccs 5
cts 5
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A guard() 0 10 2
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