1 | <?php namespace Arcanedev\Currencies\Services; |
||
16 | abstract class AbstractService implements CurrencyService |
||
17 | { |
||
18 | /* ------------------------------------------------------------------------------------------------ |
||
19 | | Properties |
||
20 | | ------------------------------------------------------------------------------------------------ |
||
21 | */ |
||
22 | /** |
||
23 | * The base URL. |
||
24 | * |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $baseUrl = ''; |
||
28 | |||
29 | /** |
||
30 | * @var \Arcanedev\Currencies\Contracts\Http\Client |
||
31 | */ |
||
32 | protected $client; |
||
33 | |||
34 | /** |
||
35 | * The cache repository. |
||
36 | * |
||
37 | * @var \Illuminate\Contracts\Cache\Repository |
||
38 | */ |
||
39 | protected $cache; |
||
40 | |||
41 | /** |
||
42 | * The enabled cache status. |
||
43 | * |
||
44 | * @var bool |
||
45 | */ |
||
46 | protected $cacheEnabled; |
||
47 | |||
48 | /** |
||
49 | * The cache key name. |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $cacheKey; |
||
54 | |||
55 | /** |
||
56 | * The cache duration. |
||
57 | * |
||
58 | * @var int |
||
59 | */ |
||
60 | protected $cacheDuration; |
||
61 | |||
62 | /* ------------------------------------------------------------------------------------------------ |
||
63 | | Constructor |
||
64 | | ------------------------------------------------------------------------------------------------ |
||
65 | */ |
||
66 | /** |
||
67 | * AbstractService constructor. |
||
68 | * |
||
69 | * @param \Arcanedev\Currencies\Contracts\Http\Client $client |
||
70 | * @param \Illuminate\Contracts\Cache\Repository $cache |
||
71 | * @param array $configs |
||
72 | */ |
||
73 | 24 | public function __construct(ClientContract $client, CacheContract $cache, array $configs = []) |
|
82 | |||
83 | /* ------------------------------------------------------------------------------------------------ |
||
84 | | Getters & Setters |
||
85 | | ------------------------------------------------------------------------------------------------ |
||
86 | */ |
||
87 | /** |
||
88 | * Get the default currency. |
||
89 | * |
||
90 | * @return string |
||
91 | */ |
||
92 | 12 | public function getDefaultCurrency() |
|
96 | |||
97 | /** |
||
98 | * Get the supported currencies. |
||
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | 12 | public function getSupportedCurrencies() |
|
106 | |||
107 | /** |
||
108 | * Get the `from` currency. |
||
109 | * |
||
110 | * @param string $from |
||
111 | * |
||
112 | * @return string |
||
113 | */ |
||
114 | 12 | protected function getFromCurrency($from) |
|
122 | |||
123 | /** |
||
124 | * Get the `to` currencies. |
||
125 | * |
||
126 | * @param array|string|null $to |
||
127 | * |
||
128 | * @return array |
||
129 | */ |
||
130 | 12 | protected function getToCurrencies($to) |
|
141 | |||
142 | /** |
||
143 | * Set the cache configs. |
||
144 | * |
||
145 | * @param array $configs |
||
146 | */ |
||
147 | 24 | protected function setCacheConfigs(array $configs) |
|
153 | |||
154 | /** |
||
155 | * Set the configs. |
||
156 | * |
||
157 | * @param array $configs |
||
158 | */ |
||
159 | abstract protected function setProviderConfigs(array $configs); |
||
160 | |||
161 | /** |
||
162 | * Get cache key. |
||
163 | * |
||
164 | * @return string |
||
165 | */ |
||
166 | protected function getCacheKey() |
||
170 | |||
171 | /** |
||
172 | * Check if cache is enabled. |
||
173 | * |
||
174 | * @return bool |
||
175 | */ |
||
176 | 12 | public function isCacheEnabled() |
|
180 | |||
181 | /* ------------------------------------------------------------------------------------------------ |
||
182 | | Main Functions |
||
183 | | ------------------------------------------------------------------------------------------------ |
||
184 | */ |
||
185 | /** |
||
186 | * Get currencies rates. |
||
187 | * |
||
188 | * @param string|null $from |
||
189 | * @param array|string|null $to |
||
190 | * |
||
191 | * @return \Arcanedev\Currencies\Entities\RateCollection |
||
192 | */ |
||
193 | 12 | public function rates($from = null, $to = null) |
|
209 | |||
210 | /** |
||
211 | * Make an API request. |
||
212 | * |
||
213 | * @param string $from |
||
214 | * @param array $to |
||
215 | * |
||
216 | * @return \Arcanedev\Currencies\Entities\RateCollection |
||
217 | */ |
||
218 | abstract protected function request($from, array $to); |
||
219 | |||
220 | /** |
||
221 | * Cache results. |
||
222 | * |
||
223 | * @param Closure $callback |
||
224 | * |
||
225 | * @return array |
||
226 | */ |
||
227 | private function cacheResults(Closure $callback) |
||
235 | |||
236 | /** |
||
237 | * Prepare rates collection. |
||
238 | * |
||
239 | * @param string $from |
||
240 | * @param array $rates |
||
241 | * |
||
242 | * @return \Arcanedev\Currencies\Entities\RateCollection |
||
243 | */ |
||
244 | 12 | protected function prepareRates($from, array $rates) |
|
248 | } |
||
249 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.