5
5
*/
6
6
namespace Magento \Framework \Locale ;
7
7
8
- use Magento \Framework \Locale \Bundle \DataBundle ;
9
-
10
8
class Format implements \Magento \Framework \Locale \FormatInterface
11
9
{
12
- /**
13
- * @var string
14
- */
15
- private static $ defaultNumberSet = 'latn ' ;
16
-
17
10
/**
18
11
* @var \Magento\Framework\App\ScopeResolverInterface
19
12
*/
@@ -68,7 +61,7 @@ public function getNumber($value)
68
61
}
69
62
70
63
if (!is_string ($ value )) {
71
- return floatval ( $ value) ;
64
+ return ( float ) $ value ;
72
65
}
73
66
74
67
//trim spaces and apostrophes
@@ -79,16 +72,15 @@ public function getNumber($value)
79
72
80
73
if ($ separatorComa !== false && $ separatorDot !== false ) {
81
74
if ($ separatorComa > $ separatorDot ) {
82
- $ value = str_replace ('. ' , '' , $ value );
83
- $ value = str_replace (', ' , '. ' , $ value );
75
+ $ value = str_replace (['. ' , ', ' ], ['' , '. ' ], $ value );
84
76
} else {
85
77
$ value = str_replace (', ' , '' , $ value );
86
78
}
87
79
} elseif ($ separatorComa !== false ) {
88
80
$ value = str_replace (', ' , '. ' , $ value );
89
81
}
90
82
91
- return floatval ( $ value) ;
83
+ return ( float ) $ value ;
92
84
}
93
85
94
86
/**
@@ -97,8 +89,6 @@ public function getNumber($value)
97
89
* @param string $localeCode Locale code.
98
90
* @param string $currencyCode Currency code.
99
91
* @return array
100
- * @SuppressWarnings(PHPMD.NPathComplexity)
101
- * @SuppressWarnings(PHPMD.CyclomaticComplexity)
102
92
*/
103
93
public function getPriceFormat ($ localeCode = null , $ currencyCode = null )
104
94
{
@@ -108,25 +98,17 @@ public function getPriceFormat($localeCode = null, $currencyCode = null)
108
98
} else {
109
99
$ currency = $ this ->_scopeResolver ->getScope ()->getCurrentCurrency ();
110
100
}
111
- $ localeData = (new DataBundle ())->get ($ localeCode );
112
- $ defaultSet = $ localeData ['NumberElements ' ]['default ' ] ?: self ::$ defaultNumberSet ;
113
- $ format = $ localeData ['NumberElements ' ][$ defaultSet ]['patterns ' ]['currencyFormat ' ]
114
- ?: ($ localeData ['NumberElements ' ][self ::$ defaultNumberSet ]['patterns ' ]['currencyFormat ' ]
115
- ?: explode ('; ' , $ localeData ['NumberPatterns ' ][1 ])[0 ]);
116
-
117
- $ decimalSymbol = $ localeData ['NumberElements ' ][$ defaultSet ]['symbols ' ]['decimal ' ]
118
- ?: ($ localeData ['NumberElements ' ][self ::$ defaultNumberSet ]['symbols ' ]['decimal ' ]
119
- ?: $ localeData ['NumberElements ' ][0 ]);
120
101
121
- $ groupSymbol = $ localeData ['NumberElements ' ][$ defaultSet ]['symbols ' ]['group ' ]
122
- ?: ($ localeData ['NumberElements ' ][self ::$ defaultNumberSet ]['symbols ' ]['group ' ]
123
- ?: $ localeData ['NumberElements ' ][1 ]);
102
+ $ formatter = new \NumberFormatter ($ localeCode , \NumberFormatter::CURRENCY );
103
+ $ format = $ formatter ->getPattern ();
104
+ $ decimalSymbol = $ formatter ->getSymbol (\NumberFormatter::DECIMAL_SEPARATOR_SYMBOL );
105
+ $ groupSymbol = $ formatter ->getSymbol (\NumberFormatter::GROUPING_SEPARATOR_SYMBOL );
124
106
125
107
$ pos = strpos ($ format , '; ' );
126
108
if ($ pos !== false ) {
127
109
$ format = substr ($ format , 0 , $ pos );
128
110
}
129
- $ format = preg_replace ("/[^0\#\.,]/ " , "" , $ format );
111
+ $ format = preg_replace ("/[^0\#\.,]/ " , '' , $ format );
130
112
$ totalPrecision = 0 ;
131
113
$ decimalPoint = strpos ($ format , '. ' );
132
114
if ($ decimalPoint !== false ) {
0 commit comments