3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Framework \Filter ;
7
8
8
9
use Exception ;
@@ -17,9 +18,9 @@ class LocalizedToNormalized implements FilterInterface
17
18
* @var array
18
19
*/
19
20
protected $ _options = [
20
- 'locale ' => null ,
21
- 'date_format ' => null ,
22
- 'precision ' => null ,
21
+ 'locale ' => null ,
22
+ 'date_format ' => null ,
23
+ 'precision ' => null ,
23
24
'decimal_style ' => null ,
24
25
];
25
26
@@ -67,14 +68,10 @@ public function setOptions(?array $options = null)
67
68
public function filter ($ value )
68
69
{
69
70
if (is_numeric ($ value )) {
70
- $ decimalStyle = $ this ->_options ['decimal_style ' ] ?? null ;
71
- if ($ decimalStyle === null ) {
72
- $ numberParse = new NumberParse ($ this ->_options ['locale ' ], NumberFormatter::PATTERN_DECIMAL );
73
- } elseif ($ decimalStyle === false ) {
74
- $ numberParse = new NumberParse ($ this ->_options ['locale ' ], NumberFormatter::DECIMAL );
75
- } else {
76
- $ numberParse = new NumberParse ($ this ->_options ['locale ' ], $ decimalStyle );
77
- }
71
+ $ numberParse = new NumberParse (
72
+ $ this ->_options ['locale ' ],
73
+ empty ($ this ->_options ['decimal_style ' ]) ? NumberFormatter::PATTERN_DECIMAL : $ this ->_options ['decimal_style ' ]
74
+ );
78
75
return (string )$ numberParse ->filter ($ value );
79
76
} elseif ($ this ->_options ['date_format ' ] === null && strpos ($ value , ': ' ) !== false ) {
80
77
$ formatter = new IntlDateFormatter (
@@ -152,7 +149,7 @@ private function parseDate($date)
152
149
$ parse [$ month ] = 'M ' ;
153
150
}
154
151
if ($ year !== false ) {
155
- $ parse [$ year ] = 'y ' ;
152
+ $ parse [$ year ] = 'y ' ;
156
153
}
157
154
preg_match_all ('/\d+/u ' , $ date , $ splitted );
158
155
$ split = false ;
@@ -192,7 +189,7 @@ private function parseDate($date)
192
189
}
193
190
if ($ split === false ) {
194
191
if (count ($ splitted [0 ]) > $ cnt ) {
195
- $ result ['year ' ] = $ splitted [0 ][$ cnt ];
192
+ $ result ['year ' ] = $ splitted [0 ][$ cnt ];
196
193
}
197
194
} else {
198
195
$ result ['year ' ] = iconv_substr ($ splitted [0 ][0 ], $ split , $ length );
0 commit comments