Region::__toString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 6
ccs 0
cts 5
cp 0
crap 6
rs 10
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