@@ -25,7 +25,7 @@ public function __construct(ECB $ecb, string $cache_file = '.ecb_cache', int $ca
2525 /**
2626 * @throws ECBException
2727 */
28- public function checkFileCache (): void
28+ private function checkFileCache (): void
2929 {
3030 if (!file_exists ($ this ->cache_file ) || time () - filemtime ($ this ->cache_file ) > $ this ->cache_timeout ) {
3131 $ this ->reloadExchangeReferences ($ this ->ecb );
@@ -36,27 +36,9 @@ public function checkFileCache(): void
3636 }
3737
3838 /**
39- * Converts foreign currency to euro
40- *
4139 * @throws ECBException
4240 */
43- public function toEuro (float $ amount , string $ currency , ?int $ precision = null )
44- {
45- return $ this ->convert ($ amount , $ currency , function ($ amount , $ rate ) use ($ precision ) {
46- $ value = $ amount / $ rate ;
47-
48- if (!is_null ($ precision )) {
49- return round ($ value , $ precision );
50- } else {
51- return $ value ;
52- }
53- });
54- }
55-
56- /**
57- * @throws ECBException
58- */
59- private function check (): void
41+ public function check (): void
6042 {
6143 if (!empty ($ this ->cache_file )) {
6244 $ this ->checkFileCache ();
@@ -88,7 +70,7 @@ public function list(bool $asArray = false): array
8870
8971 /**
9072 * @param string[]|string $currencies
91- * @return string []|string
73+ * @return float []|float
9274 * @throws ECBException
9375 */
9476 public function convert (float $ amount , $ currencies , callable $ callback )
@@ -122,28 +104,48 @@ public function convert(float $amount, $currencies, callable $callback)
122104 }
123105
124106 /**
125- * Reloads ECB exchange references
126- *
107+ * Converts foreign currency to euro
108+ * @param string[]|string $currencies
109+ * @return float[]|float
127110 * @throws ECBException
128111 */
129- public function reloadExchangeReferences ( ECB $ ecb ): void
112+ public function toEuro ( float $ amount , string $ currencies , ? int $ precision = null )
130113 {
131- $ this ->exchange_data = $ ecb ->getExchangeReferences ();
114+ return $ this ->convert ($ amount , $ currencies , function ($ amount , $ rate ) use ($ precision ) {
115+ $ value = $ amount / $ rate ;
116+
117+ if (!is_null ($ precision )) {
118+ return round ($ value , $ precision );
119+ } else {
120+ return $ value ;
121+ }
122+ });
132123 }
133124
134125 /**
135126 * Converts euro to foreign currency
136- *
127+ * @param string[]|string $currencies
128+ * @return float[]|float
137129 * @throws ECBException
138130 */
139- public function toForeign (float $ amount , string $ currency_code , ?int $ precision = null )
131+ public function toForeign (float $ amount , $ currencies , ?int $ precision = null )
140132 {
141- return $ this ->convert ($ amount , $ currency_code , function ($ amount , $ rate ) use ($ precision ) {
133+ return $ this ->convert ($ amount , $ currencies , function ($ amount , $ rate ) use ($ precision ) {
142134 $ val = $ amount * $ rate ;
143135 return !is_null ($ precision ) ? round ($ val , $ precision ) : $ val ;
144136 });
145137 }
146138
139+ /**
140+ * Reloads ECB exchange references
141+ *
142+ * @throws ECBException
143+ */
144+ public function reloadExchangeReferences (ECB $ ecb ): void
145+ {
146+ $ this ->exchange_data = $ ecb ->getExchangeReferences ();
147+ }
148+
147149 public function getECB (): ECB
148150 {
149151 return $ this ->ecb ;
0 commit comments