11
11
12
12
class LaravelAddressing
13
13
{
14
- /**
15
- * @var string
16
- */
17
- protected $ locale ;
18
-
19
- /**
20
- * @var string
21
- */
22
- protected $ fallback_locale ;
23
-
24
- /**
25
- * @var \CommerceGuys\Addressing\Country\CountryRepositoryInterface
26
- */
27
- protected $ country_repository ;
28
-
29
- /**
30
- * @var \CommerceGuys\Addressing\Subdivision\SubdivisionRepositoryInterface
31
- */
32
- protected $ subdivision_repository ;
33
-
34
- /**
35
- * @var \CommerceGuys\Addressing\AddressFormat\AddressFormatRepositoryInterface
36
- */
37
- protected $ address_format_repository ;
38
-
39
- /**
40
- * @var \Galahad\LaravelAddressing\Collection\CountryCollection
41
- */
42
- protected $ countries ;
43
-
44
- /**
45
- * @var bool
46
- */
47
- protected $ all_countries_loaded = false ;
48
-
49
- /**
50
- * Constructor.
51
- *
52
- * @param \CommerceGuys\Addressing\Country\CountryRepositoryInterface $country_repository
53
- * @param \CommerceGuys\Addressing\Subdivision\SubdivisionRepositoryInterface $subdivision_repository
54
- * @param \CommerceGuys\Addressing\AddressFormat\AddressFormatRepositoryInterface $address_format_repository
55
- * @param string $locale
56
- * @param string $fallback_locale
57
- */
14
+ protected string $ locale ;
15
+
16
+ protected string $ fallback_locale ;
17
+
18
+ protected CountryRepositoryInterface $ country_repository ;
19
+
20
+ protected SubdivisionRepositoryInterface $ subdivision_repository ;
21
+
22
+ protected AddressFormatRepositoryInterface $ address_format_repository ;
23
+
24
+ protected CountryCollection $ countries ;
25
+
26
+ protected bool $ all_countries_loaded = false ;
27
+
58
28
public function __construct (
59
29
CountryRepositoryInterface $ country_repository ,
60
30
SubdivisionRepositoryInterface $ subdivision_repository ,
61
31
AddressFormatRepositoryInterface $ address_format_repository ,
62
- $ locale = 'en ' ,
63
- $ fallback_locale = 'en '
32
+ string $ locale = 'en ' ,
33
+ string $ fallback_locale = 'en '
64
34
) {
65
35
$ this ->country_repository = $ country_repository ;
66
36
$ this ->subdivision_repository = $ subdivision_repository ;
@@ -81,7 +51,7 @@ public function __construct(
81
51
* @param string|null $locale
82
52
* @return \Galahad\LaravelAddressing\Entity\Country
83
53
*/
84
- public function country ($ country_code , $ locale = null ): ?Country
54
+ public function country (string $ country_code , ? string $ locale = null ): ?Country
85
55
{
86
56
$ country_code = strtoupper ($ country_code );
87
57
@@ -107,10 +77,11 @@ public function country($country_code, $locale = null): ?Country
107
77
* @param string|null $locale
108
78
* @return \Galahad\LaravelAddressing\Collection\CountryCollection
109
79
*/
110
- public function countries ($ locale = null ): CountryCollection
80
+ public function countries (? string $ locale = null ): CountryCollection
111
81
{
112
82
if (!$ this ->all_countries_loaded ) {
113
83
$ all_countries = $ this ->country_repository ->getAll ($ locale ?? $ this ->locale );
84
+
114
85
foreach ($ all_countries as $ country_code => $ base_country ) {
115
86
$ this ->countries ->put ($ country_code , new Country (
116
87
$ base_country ,
@@ -131,12 +102,10 @@ public function countries($locale = null): CountryCollection
131
102
* @param string $name
132
103
* @return \Galahad\LaravelAddressing\Entity\Country|null
133
104
*/
134
- public function countryByName ($ name ): ?Country
105
+ public function countryByName (string $ name ): ?Country
135
106
{
136
107
return $ this ->countries ()
137
- ->first (static function (Country $ country ) use ($ name ) {
138
- return 0 === strcasecmp ($ country ->getName (), $ name );
139
- });
108
+ ->first (fn (Country $ country ) => 0 === strcasecmp ($ country ->getName (), $ name ));
140
109
}
141
110
142
111
/**
@@ -145,7 +114,7 @@ public function countryByName($name): ?Country
145
114
* @param string $input
146
115
* @return \Galahad\LaravelAddressing\Entity\Country|null
147
116
*/
148
- public function findCountry ($ input ): ?Country
117
+ public function findCountry (string $ input ): ?Country
149
118
{
150
119
return $ this ->country ($ input ) ?? $ this ->countryByName ($ input );
151
120
}
0 commit comments