CurrencyLoader   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
B currencies() 0 26 7
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
        $currencies = array_filter(array_unique(static::$currencies[$list]), function ($item) {
39
            return is_string($item);
40
        });
41
42
        sort($currencies);
43
44
        return array_combine($currencies, $currencies);
45
    }
46
}
47