rinvex / countries

Rinvex Country is a simple and lightweight package for retrieving country details with flexibility. A whole bunch of data including name, demonym, capital, iso codes, dialling codes, geo data, currencies, flags, emoji, and other attributes for all 250 countries worldwide at your fingertips.
https://rinvex.com
MIT License
1.66k stars 208 forks source link

Error on getTld() method #64

Closed rjsworking closed 3 years ago

rjsworking commented 7 years ago

Hi Found a case where getTld() throws an error:

[Symfony\Component\Debug\Exception\FatalThrowableError]
Type error: current() expects parameter 1 to be array, null given

[2017-09-12 07:40:18] local.ERROR: Type error: current() expects parameter 1 to be array, null given {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Type error: current() expects parameter 1 to be array, null given at /var/www/projects/translations/vendor/rinvex/country/src/Country.php:249)

Case 1 - Works OK

$country = country('XK');
dd($country->getTld());

Case 2 - Works OK

$country = country('XK', false);
dd($country['tld']);

Case 3 - Works OK

$countries = countries(true);
foreach ($countries as $country) {
    dump($country['tld']);
}

Case 4 - Throws the error

$countries = countries(true, true);
foreach ($countries as $country) {
    dump($country->getTld());
}

The error only occurs for XK - Kosovo, BQ - Caribbean Netherlands and SH - Saint Helena because the get() method returns null.

Replacing return current($this->get('tld', [])) ?: null; with return $this->get('tld', []) ?: null; seems to fix the error.

Cheers

Omranic commented 3 years ago

Thank you for your patience, this is fixed in #177