Completed
Push — master ( 272924...57ae86 )
by Tobias
02:12
created

Country   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 56
ccs 9
cts 12
cp 0.75
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A getName() 0 4 1
A getCode() 0 4 1
A __toString() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Geocoder package.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT License
11
 */
12
13
namespace Geocoder\Model;
14
15
use Geocoder\Exception\InvalidArgument;
16
17
/**
18
 * A Country has either a name or a code. A Country will never be without data.
19
 *
20
 * @author William Durand <[email protected]>
21
 */
22
final class Country
23
{
24
    /**
25
     * @var string|null
26
     */
27
    private $name;
28
29
    /**
30
     * @var string|null
31
     */
32
    private $code;
33
34
    /**
35
     * @param string $name
36
     * @param string $code
37
     */
38 6
    public function __construct(string $name = null, string $code = null)
39
    {
40 6
        if (null === $name && null === $code) {
41
            throw new InvalidArgument('A country must have either a name or a code');
42
        }
43
44 6
        $this->name = $name;
45 6
        $this->code = $code;
46 6
    }
47
48
    /**
49
     * Returns the country name.
50
     *
51
     * @return string|null
52
     */
53 6
    public function getName()
54
    {
55 6
        return $this->name;
56
    }
57
58
    /**
59
     * Returns the country ISO code.
60
     *
61
     * @return string|null
62
     */
63 6
    public function getCode()
64
    {
65 6
        return $this->code;
66
    }
67
68
    /**
69
     * Returns a string with the country name.
70
     *
71
     * @return string
72
     */
73
    public function __toString(): string
74
    {
75
        return $this->getName() ?: '';
76
    }
77
}
78