Dictionary::getTripletHundred()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
/**
3
 * @link https://github.com/phpviet/number-to-words
4
 * @copyright (c) PHP Viet
5
 * @license [MIT](http://www.opensource.org/licenses/MIT)
6
 */
7
8
namespace PHPViet\NumberToWords;
9
10
use InvalidArgumentException;
11
12
/**
13
 * @author Vuong Minh <[email protected]>
14
 * @since 1.0.0
15
 */
16
class Dictionary implements DictionaryInterface
17
{
18
    /**
19
     * Mảng tập hợp hàng đơn vị.
20
     *
21
     * @var array
22
     */
23
    protected static $tripletUnits = [
24
        'không',
25
        'một',
26
        'hai',
27
        'ba',
28
        'bốn',
29
        'năm',
30
        'sáu',
31
        'bảy',
32
        'tám',
33
        'chín',
34
    ];
35
36
    /**
37
     * Mảng tập hợp hàng chục.
38
     *
39
     * @var array
40
     */
41
    protected static $tripletTens = [
42
        '',
43
        'mười',
44
        'hai mươi',
45
        'ba mươi',
46
        'bốn mươi',
47
        'năm mươi',
48
        'sáu mươi',
49
        'bảy mươi',
50
        'tám mươi',
51
        'chín mươi',
52
    ];
53
54
    /**
55
     * Từ ngữ mô tả hàng trăm.
56
     *
57
     * @var string
58
     */
59
    protected static $hundred = 'trăm';
60
61
    /**
62
     * Mảng tập hợp đơn vị tính dựa trên số mũ 3.
63
     *
64
     * @var array
65
     */
66
    protected static $exponents = [
67
        '',
68
        'nghìn',
69
        'triệu',
70
        'tỷ',
71
        'nghìn tỷ',
72
        'triệu tỷ',
73
    ];
74
75
    /**
76
     * {@inheritdoc}
77
     */
78
    public function zero(): string
79
    {
80
        return static::$tripletUnits[0];
81
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86
    public function minus(): string
87
    {
88
        return 'âm';
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94
    public function separator(): string
95
    {
96
        return ' ';
97
    }
98
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function tripletTenSeparator(): string
103
    {
104
        return 'linh';
105
    }
106
107
    /**
108
     * {@inheritdoc}
109
     */
110
    public function specialTripletUnitOne(): string
111
    {
112
        return 'mốt';
113
    }
114
115
    /**
116
     * {@inheritdoc}
117
     */
118
    public function specialTripletUnitFour(): string
119
    {
120
        return 'tư';
121
    }
122
123
    /**
124
     * {@inheritdoc}
125
     */
126
    public function specialTripletUnitFive(): string
127
    {
128
        return 'lăm';
129
    }
130
131
    /**
132
     * {@inheritdoc}
133
     */
134
    public function fraction(): string
135
    {
136
        return 'phẩy';
137
    }
138
139
    /**
140
     * {@inheritdoc}
141
     */
142 View Code Duplication
    public function getTripletUnit(int $unit): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
143
    {
144
        if (! isset(static::$tripletUnits[$unit])) {
145
            throw new InvalidArgumentException(sprintf('Unit arg (`%s`) must be in 0-9 range!', $unit));
146
        }
147
148
        return static::$tripletUnits[$unit];
149
    }
150
151
    /**
152
     * {@inheritdoc}
153
     */
154
    public function getTripletTen(int $ten): string
155
    {
156
        if (! isset(static::$tripletTens[$ten])) {
157
            throw new InvalidArgumentException(sprintf('Ten arg (`%s`) must be in 0-9 range!', $ten));
158
        }
159
160
        return static::$tripletTens[$ten];
161
    }
162
163
    /**
164
     * {@inheritdoc}
165
     */
166 View Code Duplication
    public function getTripletHundred(int $hundred): string
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
167
    {
168
        if (! isset(static::$tripletUnits[$hundred])) {
169
            throw new InvalidArgumentException(sprintf('Hundred arg (`%s`) must be in 0-9 range!', $hundred));
170
        }
171
172
        return static::$tripletUnits[$hundred].$this->separator().static::$hundred;
173
    }
174
175
    /**
176
     * {@inheritdoc}
177
     */
178
    public function getExponent(int $power): string
179
    {
180
        if (! isset(static::$exponents[$power])) {
181
            throw new InvalidArgumentException(sprintf('Power arg (`%s`) not exist in vietnamese dictionary!', $power));
182
        }
183
184
        return static::$exponents[$power];
185
    }
186
}
187