Skip to content

Commit a2112fd

Browse files
committed
Merge pull request #31 from adamdburton/patch-1
Fixes errors when countries.json file does not contain data from Steam
2 parents e5c03e7 + 1b5f7e6 commit a2112fd

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/Syntax/SteamApi/Containers/Player.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,21 @@ protected function getLocation()
8484
$countriesFile = json_decode(\file_get_contents(__DIR__ . '/../Resources/countries.json'));
8585
$result = new \stdClass;
8686

87-
if ($this->locCountryCode != null) {
87+
if ($this->locCountryCode != null && isset($countriesFile->{$this->locCountryCode})) {
8888
$result->country = $countriesFile->{$this->locCountryCode}->name;
89-
}
9089

91-
if ($this->locCountryCode != null && $this->locStateCode != null) {
92-
$result->state = $countriesFile->{$this->locCountryCode}->states->{$this->locStateCode}->name;
93-
}
90+
if ($this->locStateCode != null && isset($countriesFile->{$this->locCountryCode}->states->{$this->locStateCode})) {
91+
$result->state = $countriesFile->{$this->locCountryCode}->states->{$this->locStateCode}->name;
92+
}
9493

95-
if ($this->locCountryCode != null && $this->locStateCode != null && $this->locCityId != null) {
96-
if (! empty($countriesFile->{$this->locCountryCode}->states->{$this->locStateCode}->cities)) {
97-
$result->city = $countriesFile->{$this->locCountryCode}->states->{$this->locStateCode}->cities->{$this->locCityId}->name;
94+
if ($this->locCityId != null && isset($countriesFile->{$this->locCountryCode}->states->{$this->locStateCode}) && ! empty($countriesFile->{$this->locCountryCode}->states->{$this->locStateCode}->cities)) {
95+
if (isset($countriesFile->{$this->locCountryCode}->states->{$this->locStateCode}->cities->{$this->locCityId}))
96+
{
97+
$result->city = $countriesFile->{$this->locCountryCode}->states->{$this->locStateCode}->cities->{$this->locCityId}->name;
98+
}
9899
}
99100
}
100-
101+
101102
return $result;
102103
}
103104

0 commit comments

Comments
 (0)