|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* This file is part of the Numverify API Client for PHP. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) 2024 Eric Sizemore <[email protected]> |
|
9
|
|
|
* (c) 2018-2021 Mark Rogoyski <[email protected]> |
|
10
|
|
|
* |
|
11
|
|
|
* This source file is subject to the MIT license. For the full copyright, |
|
12
|
|
|
* license information, and credits/acknowledgements, please view the LICENSE |
|
13
|
|
|
* and README files that were distributed with this source code. |
|
14
|
|
|
*/ |
|
15
|
|
|
|
|
16
|
|
|
namespace Numverify\Country; |
|
17
|
|
|
|
|
18
|
|
|
use JsonSerializable; |
|
19
|
|
|
use Stringable; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Country |
|
23
|
|
|
* Role: Value object that represents a callable country. |
|
24
|
|
|
* |
|
25
|
|
|
* @see \Numverify\Tests\Country\CountryTest |
|
26
|
|
|
*/ |
|
27
|
|
|
readonly class Country implements JsonSerializable, Stringable |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Country constructor. |
|
31
|
|
|
*/ |
|
32
|
9 |
|
public function __construct(private string $countryCode, private string $countryName, private string $dialingCode) {} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* {@inheritDoc} |
|
36
|
|
|
* |
|
37
|
|
|
* CountryCode: CountryName (DialingCode) |
|
38
|
|
|
*/ |
|
39
|
1 |
|
public function __toString(): string |
|
40
|
|
|
{ |
|
41
|
1 |
|
return \sprintf('%s: %s (%s)', $this->countryCode, $this->countryName, $this->dialingCode); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Get country code. |
|
46
|
|
|
*/ |
|
47
|
7 |
|
public function getCountryCode(): string |
|
48
|
|
|
{ |
|
49
|
7 |
|
return $this->countryCode; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get country name. |
|
54
|
|
|
*/ |
|
55
|
7 |
|
public function getCountryName(): string |
|
56
|
|
|
{ |
|
57
|
7 |
|
return $this->countryName; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get dialing code. |
|
62
|
|
|
*/ |
|
63
|
1 |
|
public function getDialingCode(): string |
|
64
|
|
|
{ |
|
65
|
1 |
|
return $this->dialingCode; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @inheritDoc |
|
70
|
|
|
* |
|
71
|
|
|
* @return string[] |
|
72
|
|
|
*/ |
|
73
|
1 |
|
public function jsonSerialize(): array |
|
74
|
|
|
{ |
|
75
|
1 |
|
return [ |
|
76
|
1 |
|
'countryCode' => $this->countryCode, |
|
77
|
1 |
|
'countryName' => $this->countryName, |
|
78
|
1 |
|
'diallingCode' => $this->dialingCode, |
|
79
|
1 |
|
]; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|