Region   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 40%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 31
ccs 6
cts 15
cp 0.4
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getName() 0 3 1
A getCode() 0 3 1
A __toString() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CodeblogPro\GeoLocationAddress;
6
7
use CodeblogPro\GeoLocationAddress\Exceptions\InvalidArgumentException;
8
9
class Region
10
{
11
    private string $name;
12
    private ?string $code = null;
13
14 3
    public function __construct(string $name = null, string $code = null)
15
    {
16 3
        if (null === $name) {
17 1
            throw new InvalidArgumentException('A region must have either a name.');
18
        }
19
20 2
        $this->name = $name;
21 2
        $this->code = $code;
22 2
    }
23
24
    public function getName()
25
    {
26
        return $this->name;
27
    }
28
29
    public function getCode()
30
    {
31
        return $this->code;
32
    }
33
34
    public function __toString(): string
35
    {
36
        return $this->getName()
37
        . !empty($this->getCode())
38
            ? '(' . $this->getCode() . ')'
39
            : '';
40
    }
41
}
42