1
1
<?php
2
2
3
- declare (strict_types=1 );
4
-
5
3
namespace Laminas \I18n \View \Helper ;
6
4
7
5
use Laminas \View \Helper \AbstractHelper ;
@@ -23,58 +21,75 @@ class NumberFormat extends AbstractHelper
23
21
24
22
/**
25
23
* The maximum number of decimals to use.
24
+ *
25
+ * @var int
26
26
*/
27
- protected ? int $ maxDecimals = null ;
27
+ protected $ maxDecimals ;
28
28
29
29
/**
30
30
* The minimum number of decimals to use.
31
+ *
32
+ * @var int
31
33
*/
32
- protected ? int $ minDecimals = null ;
34
+ protected $ minDecimals ;
33
35
34
36
/**
35
37
* NumberFormat style to use
38
+ *
39
+ * @var int
36
40
*/
37
- protected ? int $ formatStyle = null ;
41
+ protected $ formatStyle ;
38
42
39
43
/**
40
44
* NumberFormat type to use
45
+ *
46
+ * @var int
41
47
*/
42
- protected ? int $ formatType = null ;
48
+ protected $ formatType ;
43
49
44
50
/**
45
51
* Formatter instances
46
52
*
47
53
* @var array<string, NumberFormatter>
48
54
*/
49
- protected array $ formatters = [];
55
+ protected $ formatters = [];
50
56
51
57
/**
52
58
* Text attributes.
53
59
*
54
60
* @var array<int, string>
55
61
*/
56
- protected array $ textAttributes = [];
62
+ protected $ textAttributes = [];
57
63
58
64
/**
59
65
* Locale to use instead of the default
66
+ *
67
+ * @var string
60
68
*/
61
- protected ? string $ locale = null ;
69
+ protected $ locale ;
62
70
63
71
/**
64
72
* Format a number
65
73
*
66
- * @param int|float $number
67
- * @param array<int, string> $textAttributes
74
+ * @param int|float $number
75
+ * @param int|null $formatStyle
76
+ * @param int|null $formatType
77
+ * @param string|null $locale
78
+ * @param int|null $maxDecimals
79
+ * @param array<int, string> $textAttributes
80
+ * @param int|float $number
81
+ * @param int|null $minDecimals
82
+ * @return string
68
83
*/
69
84
public function __invoke (
70
85
$ number ,
71
- ? int $ formatStyle = null ,
72
- ? int $ formatType = null ,
73
- ? string $ locale = null ,
74
- ? int $ maxDecimals = null ,
86
+ $ formatStyle = null ,
87
+ $ formatType = null ,
88
+ $ locale = null ,
89
+ $ maxDecimals = null ,
75
90
?array $ textAttributes = null ,
76
- ? int $ minDecimals = null
77
- ): string {
91
+ $ minDecimals = null
92
+ ) {
78
93
if (null === $ locale ) {
79
94
$ locale = $ this ->getLocale ();
80
95
}
@@ -128,17 +143,22 @@ public function __invoke(
128
143
129
144
/**
130
145
* Set format style to use instead of the default
146
+ *
147
+ * @param int $formatStyle
148
+ * @return $this
131
149
*/
132
- public function setFormatStyle (int $ formatStyle ): self
150
+ public function setFormatStyle ($ formatStyle )
133
151
{
134
- $ this ->formatStyle = $ formatStyle ;
152
+ $ this ->formatStyle = ( int ) $ formatStyle ;
135
153
return $ this ;
136
154
}
137
155
138
156
/**
139
157
* Get the format style to use
158
+ *
159
+ * @return int
140
160
*/
141
- public function getFormatStyle (): int
161
+ public function getFormatStyle ()
142
162
{
143
163
if (null === $ this ->formatStyle ) {
144
164
$ this ->formatStyle = NumberFormatter::DECIMAL ;
@@ -149,17 +169,22 @@ public function getFormatStyle(): int
149
169
150
170
/**
151
171
* Set format type to use instead of the default
172
+ *
173
+ * @param int $formatType
174
+ * @return $this
152
175
*/
153
- public function setFormatType (? int $ formatType ): self
176
+ public function setFormatType ($ formatType )
154
177
{
155
- $ this ->formatType = $ formatType ;
178
+ $ this ->formatType = ( int ) $ formatType ;
156
179
return $ this ;
157
180
}
158
181
159
182
/**
160
183
* Get the format type to use
184
+ *
185
+ * @return int
161
186
*/
162
- public function getFormatType (): int
187
+ public function getFormatType ()
163
188
{
164
189
if (null === $ this ->formatType ) {
165
190
$ this ->formatType = NumberFormatter::TYPE_DEFAULT ;
@@ -168,9 +193,12 @@ public function getFormatType(): int
168
193
}
169
194
170
195
/**
171
- * Set number (both min & max) of decimals to use instead of the default.
196
+ * Set number of decimals (both min & max) to use instead of the default.
197
+ *
198
+ * @param int $decimals
199
+ * @return $this
172
200
*/
173
- public function setDecimals (? int $ decimals ): self
201
+ public function setDecimals ($ decimals )
174
202
{
175
203
$ this ->minDecimals = $ decimals ;
176
204
$ this ->maxDecimals = $ decimals ;
@@ -179,59 +207,76 @@ public function setDecimals(?int $decimals): self
179
207
180
208
/**
181
209
* Set the maximum number of decimals to use instead of the default.
210
+ *
211
+ * @param int $maxDecimals
212
+ * @return $this
182
213
*/
183
- public function setMaxDecimals (? int $ maxDecimals ): self
214
+ public function setMaxDecimals ($ maxDecimals )
184
215
{
185
216
$ this ->maxDecimals = $ maxDecimals ;
186
217
return $ this ;
187
218
}
188
219
189
220
/**
190
221
* Set the minimum number of decimals to use instead of the default.
222
+ *
223
+ * @param int $minDecimals
224
+ * @return $this
191
225
*/
192
- public function setMinDecimals (? int $ minDecimals ): self
226
+ public function setMinDecimals ($ minDecimals )
193
227
{
194
228
$ this ->minDecimals = $ minDecimals ;
195
229
return $ this ;
196
230
}
197
231
198
232
/**
199
233
* Get number of decimals.
234
+ *
235
+ * @return int
200
236
*/
201
- public function getDecimals (): ? int
237
+ public function getDecimals ()
202
238
{
203
239
return $ this ->maxDecimals ;
204
240
}
205
241
206
242
/**
207
243
* Get the maximum number of decimals.
244
+ *
245
+ * @return int
208
246
*/
209
- public function getMaxDecimals (): ? int
247
+ public function getMaxDecimals ()
210
248
{
211
249
return $ this ->maxDecimals ;
212
250
}
213
251
214
252
/**
215
253
* Get the minimum number of decimals.
254
+ *
255
+ * @return int
216
256
*/
217
- public function getMinDecimals (): ? int
257
+ public function getMinDecimals ()
218
258
{
219
259
return $ this ->minDecimals ;
220
260
}
221
261
222
262
/**
223
263
* Set locale to use instead of the default.
264
+ *
265
+ * @param string $locale
266
+ * @return $this
224
267
*/
225
- public function setLocale (? string $ locale ): self
268
+ public function setLocale ($ locale )
226
269
{
227
- $ this ->locale = $ locale ;
270
+ $ this ->locale = ( string ) $ locale ;
228
271
return $ this ;
229
272
}
230
273
231
274
/**
232
275
* Get the locale to use
276
+ *
277
+ * @return string
233
278
*/
234
- public function getLocale (): string
279
+ public function getLocale ()
235
280
{
236
281
if ($ this ->locale === null ) {
237
282
$ this ->locale = Locale::getDefault ();
@@ -243,15 +288,16 @@ public function getLocale(): string
243
288
/**
244
289
* @return array<int, string>
245
290
*/
246
- public function getTextAttributes (): array
291
+ public function getTextAttributes ()
247
292
{
248
293
return $ this ->textAttributes ;
249
294
}
250
295
251
296
/**
252
297
* @param array<int, string> $textAttributes
298
+ * @return $this
253
299
*/
254
- public function setTextAttributes (array $ textAttributes ): self
300
+ public function setTextAttributes (array $ textAttributes )
255
301
{
256
302
$ this ->textAttributes = $ textAttributes ;
257
303
return $ this ;
0 commit comments