Passed
Push — master ( 8b5ce5...b7fcc1 )
by Sebastian
12:08
created

CurrencyCollection::choose()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
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_Currency_CAD;
12
use AppLocalize\Localization_Currency_CHF;
13
use AppLocalize\Localization_Currency_EUR;
14
use AppLocalize\Localization_Currency_GBP;
15
use AppLocalize\Localization_Currency_MXN;
16
use AppLocalize\Localization_Currency_PLN;
17
use AppLocalize\Localization_Currency_RON;
18
use AppLocalize\Localization_Currency_USD;
19
use AppUtils\Collections\BaseStringPrimaryCollection;
20
21
/**
22
 * @package Localization
23
 * @subpackage Currencies
24
 *
25
 * @method CurrencyInterface getByID(string $id)
26
 * @method CurrencyInterface getDefault()
27
 * @method CurrencyInterface[] getAll()
28
 */
29
class CurrencyCollection extends BaseStringPrimaryCollection
30
{
31
    private static ?CurrencyCollection $instance = null;
32
33
    private function __construct()
34
    {
35
    }
36
37
    public static function getInstance(): CurrencyCollection
38
    {
39
        if (self::$instance === null) {
40
            self::$instance = new self();
41
        }
42
43
        return self::$instance;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::instance could return the type null which is incompatible with the type-hinted return AppLocalize\Localization...cies\CurrencyCollection. Consider adding an additional type-check to rule them out.
Loading history...
44
    }
45
46
    public function getDefaultID(): string
47
    {
48
        return Localization_Currency_USD::ISO_CODE;
49
    }
50
51
    protected function registerItems(): void
52
    {
53
        $this->registerItem(new Localization_Currency_CAD());
54
        $this->registerItem(new Localization_Currency_CHF());
55
        $this->registerItem(new Localization_Currency_EUR());
56
        $this->registerItem(new Localization_Currency_GBP());
57
        $this->registerItem(new Localization_Currency_MXN());
58
        $this->registerItem(new Localization_Currency_PLN());
59
        $this->registerItem(new Localization_Currency_RON());
60
        $this->registerItem(new Localization_Currency_USD());
61
    }
62
63
    private ?CannedCurrencies $canned = null;
64
65
    public function choose() : CannedCurrencies
66
    {
67
        if(!isset($this->canned)) {
68
            $this->canned = new CannedCurrencies();
69
        }
70
71
        return $this->canned;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->canned could return the type null which is incompatible with the type-hinted return AppLocalize\Localization...encies\CannedCurrencies. Consider adding an additional type-check to rule them out.
Loading history...
72
    }
73
}
74