1 | <?php |
||
11 | class ApiClient |
||
12 | { |
||
13 | |||
14 | const CACHE_KEY = 'nbrb-xml-cache'; |
||
15 | |||
16 | |||
17 | /** |
||
18 | * Получение официального курса белорусского рубля по отношению к иностранным валютам на определенную дату |
||
19 | * |
||
20 | * @var string |
||
21 | */ |
||
22 | private $urlExchangeRates = 'http://www.nbrb.by/Services/XmlExRates.aspx'; |
||
23 | |||
24 | /** |
||
25 | * Получение динамики официального курса белорусского рубля по отношению к заданной иностранной валюте, |
||
26 | * устанавливаемого Национальным банком Республики Беларусь (не более чем за 365 дней): |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | private $urlExchangeRatesDynamic = 'http://www.nbrb.by/Services/XmlExRatesDyn.aspx'; |
||
31 | |||
32 | /** |
||
33 | * @var Client |
||
34 | */ |
||
35 | private $client; |
||
36 | |||
37 | /** |
||
38 | * @var int |
||
39 | */ |
||
40 | private $httpConnectTimeout; |
||
41 | |||
42 | /** |
||
43 | * @var int |
||
44 | */ |
||
45 | private $httpTimeout; |
||
46 | |||
47 | /** |
||
48 | * ApiClient constructor. |
||
49 | * @param string $urlExchangeRates |
||
50 | * @param string $urlExchangeRatesDynamic |
||
51 | * @param int $httpConnectTimeout |
||
52 | * @param int $httpTimeout |
||
53 | */ |
||
54 | public function __construct($urlExchangeRates, $urlExchangeRatesDynamic, $httpConnectTimeout, $httpTimeout) |
||
61 | |||
62 | |||
63 | /** |
||
64 | * @return Client |
||
65 | */ |
||
66 | public function getClient() |
||
74 | |||
75 | |||
76 | /** |
||
77 | * Курсы валют за дату |
||
78 | * |
||
79 | * @param \DateTime $date |
||
80 | * @param bool $quotName |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | public function getXmlExchangesRates(\DateTime $date, $quotName = true) |
||
97 | |||
98 | |||
99 | /** |
||
100 | * Динамика курса |
||
101 | * |
||
102 | * @param $currencyId |
||
103 | * @param \DateTime $firstDate |
||
104 | * @param \DateTime $lastDate |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | public function getXmlExchangesRatesDynamic($currencyId, \DateTime $firstDate, \DateTime $lastDate) |
||
118 | |||
119 | |||
120 | /** |
||
121 | * Возвращает XML документ |
||
122 | * @param $url |
||
123 | * @param $query |
||
124 | * @return string |
||
125 | */ |
||
126 | private function getResponseBody($url, $query) |
||
136 | |||
137 | } |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.