BaseCurrency::isCurrencyKnown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * @package Localization
4
 * @subpackage Currencies
5
 */
6
7
declare(strict_types=1);
8
9
namespace AppLocalize\Localization\Currencies;
10
11
use AppLocalize\Localization;
12
use AppLocalize\Localization\Countries\CountryInterface;
13
14
/**
15
 * Individual currency representation.
16
 *
17
 * @package Localization
18
 * @subpackage Currencies
19
 * @author Sebastian Mordziol <[email protected]>
20
 */
21
abstract class BaseCurrency implements CurrencyInterface
22
{
23
    /**
24
     * Creates a new currency object.
25
     *
26
     * @param string $id
27
     * @return CurrencyInterface
28
     * @deprecated Use the collection {@see Localization::createCurrencies()} instead.
29
     */
30
    public static function create(string $id) : CurrencyInterface
31
    {
32
        return Localization::createCurrencies()->getByID($id);
33
    }
34
35
    public function __construct()
36
    {
37
    }
38
39
    public function getID(): string
40
    {
41
        return $this->getISO();
42
    }
43
44
    /**
45
     * Gets all countries that this currency is used in.
46
     * @return CountryInterface[]
47
     */
48
    public function getCountries() : array
49
    {
50
        $countries = array();
51
        $iso = $this->getISO();
52
53
        foreach(Localization::createCountries()->getAll() as $country) {
54
            if($country->getCurrencyISO() === $iso) {
55
                $countries[] = $country;
56
            }
57
        }
58
59
        return $countries;
60
    }
61
62
    /**
63
     * Checks whether the specified currency name is known
64
     * (supported by the application)
65
     *
66
     * @param string $currencyName Currency code, e.g. {@see Localization_Currency_USD::ISO_CODE}.
67
     * @return boolean
68
     * @deprecated Use {@see CurrencyCollection::idExists()} instead.
69
     */
70
    public static function isCurrencyKnown(string $currencyName) : bool
71
    {
72
        return Localization::createCurrencies()->idExists($currencyName);
73
    }
74
75
    /**
76
     * Returns the singular of the currency label.
77
     *
78
     * @return string
79
     */
80
    public function __toString()
81
    {
82
        return $this->getSingular();
83
    }
84
85
    public function getPreferredSymbol(): string
86
    {
87
        if($this->isNamePreferred()) {
88
            return $this->getISO();
89
        }
90
91
        return $this->getSymbol();
92
    }
93
}
94