|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Copyright 2014 SURFnet bv |
|
5
|
|
|
* |
|
6
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
7
|
|
|
* you may not use this file except in compliance with the License. |
|
8
|
|
|
* You may obtain a copy of the License at |
|
9
|
|
|
* |
|
10
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
11
|
|
|
* |
|
12
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
13
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
14
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15
|
|
|
* See the License for the specific language governing permissions and |
|
16
|
|
|
* limitations under the License. |
|
17
|
|
|
*/ |
|
18
|
|
|
|
|
19
|
|
|
namespace Surfnet\StepupBundle\Value\PhoneNumber; |
|
20
|
|
|
|
|
21
|
|
|
final class Country |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @var CountryCode |
|
25
|
|
|
*/ |
|
26
|
|
|
private $countryCode; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var string |
|
30
|
|
|
*/ |
|
31
|
|
|
private $countryName; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param CountryCode $countryCode |
|
35
|
|
|
* @param string $countryName |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(CountryCode $countryCode, $countryName) |
|
38
|
|
|
{ |
|
39
|
|
|
if (!is_string($countryName)) { |
|
40
|
|
|
throw InvalidArgumentException::invalidType('string', 'countryName', $countryName); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$this->countryCode = $countryCode; |
|
44
|
|
|
$this->countryName = $countryName; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @return CountryCode |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getCountryCode() |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->countryCode; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @return string |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getCountryName() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->countryName; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param self $other |
|
|
|
|
|
|
65
|
|
|
* @return bool |
|
66
|
|
|
*/ |
|
67
|
|
|
public function equals(self $other) |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->countryName === $other->name && $this->countryCode->equals($other->countryCode); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function __toString() |
|
73
|
|
|
{ |
|
74
|
|
|
return sprintf('%s (%s)', $this->countryName, $this->countryCode); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.