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

CountryCollection::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 Countries
5
 */
6
7
declare(strict_types=1);
8
9
namespace AppLocalize\Localization\Countries;
10
11
use AppLocalize\Localization_Country_AT;
12
use AppLocalize\Localization_Country_CA;
13
use AppLocalize\Localization_Country_DE;
14
use AppLocalize\Localization_Country_ES;
15
use AppLocalize\Localization_Country_FR;
16
use AppLocalize\Localization_Country_IT;
17
use AppLocalize\Localization_Country_MX;
18
use AppLocalize\Localization_Country_PL;
19
use AppLocalize\Localization_Country_RO;
20
use AppLocalize\Localization_Country_UK;
21
use AppLocalize\Localization_Country_US;
22
use AppLocalize\Localization_Country_ZZ;
23
use AppUtils\Collections\BaseStringPrimaryCollection;
24
25
/**
26
 * Country collection that gives access to all available
27
 * countries and their data.
28
 *
29
 * @package Localization
30
 * @subpackage Countries
31
 *
32
 * @method BaseCountry getByID(string $id)
33
 * @method BaseCountry getDefault()
34
 * @method BaseCountry[] getAll()
35
 */
36
class CountryCollection extends BaseStringPrimaryCollection
37
{
38
    private static ?CountryCollection $instance = null;
39
40
    private function __construct()
41
    {
42
    }
43
44
    public static function getInstance(): CountryCollection
45
    {
46
        if (self::$instance === null) {
47
            self::$instance = new self();
48
        }
49
50
        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...tries\CountryCollection. Consider adding an additional type-check to rule them out.
Loading history...
51
    }
52
53
    public function getDefaultID(): string
54
    {
55
        return Localization_Country_US::ISO_CODE;
56
    }
57
58
    protected function registerItems(): void
59
    {
60
        $this->registerItem(new Localization_Country_AT());
61
        $this->registerItem(new Localization_Country_CA());
62
        $this->registerItem(new Localization_Country_DE());
63
        $this->registerItem(new Localization_Country_ES());
64
        $this->registerItem(new Localization_Country_FR());
65
        $this->registerItem(new Localization_Country_IT());
66
        $this->registerItem(new Localization_Country_MX());
67
        $this->registerItem(new Localization_Country_PL());
68
        $this->registerItem(new Localization_Country_RO());
69
        $this->registerItem(new Localization_Country_UK());
70
        $this->registerItem(new Localization_Country_US());
71
        $this->registerItem(new Localization_Country_ZZ());
72
    }
73
74
    private ?CannedCountries $canned = null;
75
76
    public function choose() : CannedCountries
77
    {
78
        if(!isset($this->canned)) {
79
            $this->canned = new CannedCountries();
80
        }
81
82
        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\Countries\CannedCountries. Consider adding an additional type-check to rule them out.
Loading history...
83
    }
84
}
85