Skip to content

Commit f524dee

Browse files
committed
Add type hints to root class
1 parent 5d1c677 commit f524dee

File tree

1 file changed

+22
-53
lines changed

1 file changed

+22
-53
lines changed

src/LaravelAddressing.php

Lines changed: 22 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,56 +11,26 @@
1111

1212
class LaravelAddressing
1313
{
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+
5828
public function __construct(
5929
CountryRepositoryInterface $country_repository,
6030
SubdivisionRepositoryInterface $subdivision_repository,
6131
AddressFormatRepositoryInterface $address_format_repository,
62-
$locale = 'en',
63-
$fallback_locale = 'en'
32+
string $locale = 'en',
33+
string $fallback_locale = 'en'
6434
) {
6535
$this->country_repository = $country_repository;
6636
$this->subdivision_repository = $subdivision_repository;
@@ -81,7 +51,7 @@ public function __construct(
8151
* @param string|null $locale
8252
* @return \Galahad\LaravelAddressing\Entity\Country
8353
*/
84-
public function country($country_code, $locale = null): ?Country
54+
public function country(string $country_code, ?string $locale = null): ?Country
8555
{
8656
$country_code = strtoupper($country_code);
8757

@@ -107,10 +77,11 @@ public function country($country_code, $locale = null): ?Country
10777
* @param string|null $locale
10878
* @return \Galahad\LaravelAddressing\Collection\CountryCollection
10979
*/
110-
public function countries($locale = null): CountryCollection
80+
public function countries(?string $locale = null): CountryCollection
11181
{
11282
if (!$this->all_countries_loaded) {
11383
$all_countries = $this->country_repository->getAll($locale ?? $this->locale);
84+
11485
foreach ($all_countries as $country_code => $base_country) {
11586
$this->countries->put($country_code, new Country(
11687
$base_country,
@@ -131,12 +102,10 @@ public function countries($locale = null): CountryCollection
131102
* @param string $name
132103
* @return \Galahad\LaravelAddressing\Entity\Country|null
133104
*/
134-
public function countryByName($name): ?Country
105+
public function countryByName(string $name): ?Country
135106
{
136107
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));
140109
}
141110

142111
/**
@@ -145,7 +114,7 @@ public function countryByName($name): ?Country
145114
* @param string $input
146115
* @return \Galahad\LaravelAddressing\Entity\Country|null
147116
*/
148-
public function findCountry($input): ?Country
117+
public function findCountry(string $input): ?Country
149118
{
150119
return $this->country($input) ?? $this->countryByName($input);
151120
}

0 commit comments

Comments
 (0)