Passed
Push — country_details ( 007c62 )
by De
04:31
created

Country::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 8
dl 0
loc 18
rs 10
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Sokil\IsoCodes\Database\Countries;
6
7
use Sokil\IsoCodes\Database\Countries;
8
use Sokil\IsoCodes\TranslationDriver\TranslatorInterface;
9
10
class Country
11
{
12
    /**
13
     * @var string
14
     */
15
    private $name;
16
17
    /**
18
     * @var string|null
19
     */
20
    private $localName;
21
22
    /**
23
     * @var string
24
     */
25
    private $alpha2;
26
27
    /**
28
     * @var string
29
     */
30
    private $alpha3;
31
32
    /**
33
     * @var string
34
     */
35
    private $numericCode;
36
37
    /**
38
     * Emoji of country flag
39
     *
40
     * @var string
41
     */
42
    private $flag;
43
44
    /**
45
     * @var string
46
     */
47
    private $officialName;
48
49
    /**
50
     * @var string
51
     */
52
    private $commonName;
53
54
    /**
55
     * @var TranslatorInterface
56
     */
57
    private $translator;
58
59
    public function __construct(
60
        TranslatorInterface $translator,
61
        string $name,
62
        string $alpha2,
63
        string $alpha3,
64
        string $numericCode,
65
        string $flag,
66
        ?string $officialName = null,
67
        ?string $commonName = null
68
    ) {
69
        $this->translator = $translator;
70
        $this->name = $name;
71
        $this->alpha2 = $alpha2;
72
        $this->alpha3 = $alpha3;
73
        $this->numericCode = $numericCode;
74
        $this->flag = $flag;
75
        $this->officialName = $officialName;
76
        $this->commonName = $commonName;
77
    }
78
79
    public function getAlpha2(): string
80
    {
81
        return $this->alpha2;
82
    }
83
84
    public function getAlpha3(): string
85
    {
86
        return $this->alpha3;
87
    }
88
89
    public function getNumericCode(): string
90
    {
91
        return $this->numericCode;
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function getFlag(): string
98
    {
99
        return $this->flag;
100
    }
101
102
    public function getName(): string
103
    {
104
        return $this->name;
105
    }
106
107
    public function getLocalName(): string
108
    {
109
        if ($this->localName === null) {
110
            $this->localName = $this->translator->translate(
111
                Countries::getISONumber(),
112
                $this->name
113
            );
114
        }
115
116
        return $this->localName;
117
    }
118
119
    public function getOfficialName(): ?string
120
    {
121
        return $this->officialName;
122
    }
123
124
    public function getCommonName(): ?string
125
    {
126
        return $this->commonName;
127
    }
128
}
129