18
18
/**
19
19
* Currency rate import model (https://apilayer.com/marketplace/fixer-api)
20
20
*/
21
- class FixerIoApiLayer implements \ Magento \ Directory \ Model \ Currency \ Import \ ImportInterface
21
+ class FixerIoApiLayer implements ImportInterface
22
22
{
23
23
private const CURRENCY_CONVERTER_HOST = 'https://api.apilayer.com ' ;
24
24
private const CURRENCY_CONVERTER_URL_PATH = '/fixer/latest? '
@@ -27,7 +27,7 @@ class FixerIoApiLayer implements \Magento\Directory\Model\Currency\Import\Import
27
27
/**
28
28
* @var array
29
29
*/
30
- private $ _messages = [];
30
+ private $ messages = [];
31
31
32
32
/**
33
33
* @var HttpClientFactory
@@ -37,7 +37,7 @@ class FixerIoApiLayer implements \Magento\Directory\Model\Currency\Import\Import
37
37
/**
38
38
* @var CurrencyFactory
39
39
*/
40
- private $ _currencyFactory ;
40
+ private $ currencyFactory ;
41
41
42
42
/**
43
43
* Core scope config
@@ -58,7 +58,7 @@ public function __construct(
58
58
ScopeConfigInterface $ scopeConfig ,
59
59
HttpClientFactory $ httpClientFactory
60
60
) {
61
- $ this ->_currencyFactory = $ currencyFactory ;
61
+ $ this ->currencyFactory = $ currencyFactory ;
62
62
$ this ->scopeConfig = $ scopeConfig ;
63
63
$ this ->httpClientFactory = $ httpClientFactory ;
64
64
}
@@ -71,7 +71,7 @@ public function __construct(
71
71
public function importRates ()
72
72
{
73
73
$ data = $ this ->fetchRates ();
74
- $ this ->_saveRates ($ data );
74
+ $ this ->saveRates ($ data );
75
75
return $ this ;
76
76
}
77
77
@@ -81,8 +81,8 @@ public function importRates()
81
81
public function fetchRates ()
82
82
{
83
83
$ data = [];
84
- $ currencies = $ this ->_getCurrencyCodes ();
85
- $ defaultCurrencies = $ this ->_getDefaultCurrencyCodes ();
84
+ $ currencies = $ this ->getCurrencyCodes ();
85
+ $ defaultCurrencies = $ this ->getDefaultCurrencyCodes ();
86
86
87
87
foreach ($ defaultCurrencies as $ currencyFrom ) {
88
88
if (!isset ($ data [$ currencyFrom ])) {
@@ -99,7 +99,7 @@ public function fetchRates()
99
99
*/
100
100
public function getMessages ()
101
101
{
102
- return $ this ->_messages ;
102
+ return $ this ->messages ;
103
103
}
104
104
105
105
/**
@@ -114,7 +114,7 @@ private function convertBatch(array $data, string $currencyFrom, array $currenci
114
114
{
115
115
$ accessKey = $ this ->scopeConfig ->getValue ('currency/fixerio_apilayer/api_key ' , ScopeInterface::SCOPE_STORE );
116
116
if (empty ($ accessKey )) {
117
- $ this ->_messages [] = __ ('No API Key was specified or an invalid API Key was specified. ' );
117
+ $ this ->messages [] = __ ('No API Key was specified or an invalid API Key was specified. ' );
118
118
$ data [$ currencyFrom ] = $ this ->makeEmptyResponse ($ currenciesTo );
119
119
return $ data ;
120
120
}
@@ -144,7 +144,7 @@ private function convertBatch(array $data, string $currencyFrom, array $currenci
144
144
} else {
145
145
if (empty ($ response ['rates ' ][$ currencyTo ])) {
146
146
$ message = 'We can \'t retrieve a rate from %1 for %2. ' ;
147
- $ this ->_messages [] = __ ($ message , self ::CURRENCY_CONVERTER_HOST , $ currencyTo );
147
+ $ this ->messages [] = __ ($ message , self ::CURRENCY_CONVERTER_HOST , $ currencyTo );
148
148
$ data [$ currencyFrom ][$ currencyTo ] = null ;
149
149
} else {
150
150
$ data [$ currencyFrom ][$ currencyTo ] = (double )$ response ['rates ' ][$ currencyTo ];
@@ -160,10 +160,10 @@ private function convertBatch(array $data, string $currencyFrom, array $currenci
160
160
* @param array $rates
161
161
* @return \Magento\Directory\Model\Currency\Import\FixerIoApiLayer
162
162
*/
163
- private function _saveRates (array $ rates )
163
+ private function saveRates (array $ rates )
164
164
{
165
165
foreach ($ rates as $ currencyCode => $ currencyRates ) {
166
- $ this ->_currencyFactory ->create ()->setId ($ currencyCode )->setRates ($ currencyRates )->save ();
166
+ $ this ->currencyFactory ->create ()->setId ($ currencyCode )->setRates ($ currencyRates )->save ();
167
167
}
168
168
return $ this ;
169
169
}
@@ -234,7 +234,7 @@ private function validateResponse(array $response, string $baseCurrency): bool
234
234
201 => __ ('An invalid base currency has been entered. ' ),
235
235
];
236
236
237
- $ this ->_messages [] = $ errorCodes [$ response ['error ' ]['code ' ]] ?? __ ('Currency rates can \'t be retrieved. ' );
237
+ $ this ->messages [] = $ errorCodes [$ response ['error ' ]['code ' ]] ?? __ ('Currency rates can \'t be retrieved. ' );
238
238
239
239
return false ;
240
240
}
@@ -244,18 +244,18 @@ private function validateResponse(array $response, string $baseCurrency): bool
244
244
*
245
245
* @return array
246
246
*/
247
- private function _getCurrencyCodes ()
247
+ private function getCurrencyCodes ()
248
248
{
249
- return $ this ->_currencyFactory ->create ()->getConfigAllowCurrencies ();
249
+ return $ this ->currencyFactory ->create ()->getConfigAllowCurrencies ();
250
250
}
251
251
252
252
/**
253
253
* Retrieve default currency codes
254
254
*
255
255
* @return array
256
256
*/
257
- private function _getDefaultCurrencyCodes ()
257
+ private function getDefaultCurrencyCodes ()
258
258
{
259
- return $ this ->_currencyFactory ->create ()->getConfigBaseCurrencies ();
259
+ return $ this ->currencyFactory ->create ()->getConfigBaseCurrencies ();
260
260
}
261
261
}
0 commit comments