Completed
Push — master ( 846562...c18cbd )
by Abdelrahman
02:37 queued 01:33
created

CurrencyLoader::currencies()   B

Complexity

Conditions 7
Paths 4

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 4
nop 1
dl 0
loc 20
rs 8.6666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Country;
6
7
class CurrencyLoader
8
{
9
    protected static $currencies = [];
10
11
    /**
12
     * Retrive all the currencies of all countries.
13
     *
14
     * @param bool $longlist states if need all the details of the currencies or only the keys
15
     *
16
     * @throws \Rinvex\Country\CountryLoaderException
17
     *
18
     * @return array
19
     */
20
    public static function currencies($longlist = false): array
21
    {
22
        $list = $longlist ? 'longlist' : 'shortlist';
23
24
        if (! isset(static::$currencies[$list])) {
25
            $countries = CountryLoader::countries($longlist);
26
27
            foreach ($countries as $country) {
28
                if ($longlist) {
29
                    foreach ($country['currency'] as $currency => $details) {
30
                        static::$currencies[$list][$currency] = $longlist ? $details : $currency;
31
                    }
32
                } else {
33
                    static::$currencies[$list][] = $country['currency'];
34
                }
35
            }
36
        }
37
38
        return static::$currencies[$list];
39
    }
40
}
41