Skip to content

Commit 3e7076c

Browse files
author
Vítězslav Dvořák
committed
Enhance documentation and type hints in ExchangeRate class methods
1 parent 5c6d92f commit 3e7076c

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/SpojeNet/Cnb/ExchangeRate.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ public function __construct()
4141
parent::__construct();
4242
}
4343

44+
/**
45+
* @return array<string, string>
46+
*/
4447
public function getCurrencyList(): array
4548
{
4649
return $this->currencies;
@@ -68,10 +71,11 @@ public function exchangeRateRaw(string $datum): string
6871
/**
6972
* Convert CNB CSV to Array.
7073
*
71-
* @return array<string, array<string, string>>
74+
* @return array<string, array<string, float|int|string>>
7275
*/
7376
public function cnbCsv2Data(string $ratesRaw): array
7477
{
78+
$rates = [];
7579
$data = strstr($ratesRaw, "\n") ? explode("\n", $ratesRaw) : [];
7680

7781
unset($data[0], $data[1]);
@@ -132,12 +136,17 @@ public function shiftDays(): void
132136
$this->dropOlder($this->getKeepDays());
133137
}
134138

135-
public function getRateInfo($currency, $age): array
139+
/**
140+
* Get exchange rate for currency.
141+
*
142+
* @return array<string, array<string, float|int|string>>
143+
*/
144+
public function getRateInfo(string $currency, int $age): array
136145
{
137146
$rateInfo = $this->getColumnsFromSQL(['*'], ['code' => $currency, 'date' => self::dateBeforeDays($age)]);
138147

139148
if ($rateInfo) {
140-
$result = $rateInfo[0];
149+
$result = current($rateInfo);
141150
} else {
142151
$result = $this->storeDay($age)[$currency];
143152
}
@@ -151,4 +160,9 @@ public static function dateBeforeDays(int $daysBack): string
151160
{
152161
return date('Y-m-d', $daysBack ? strtotime('-'.(string) $daysBack.' day') : null);
153162
}
163+
164+
public function getHttpCode(): int
165+
{
166+
return $this->httpcode;
167+
}
154168
}

0 commit comments

Comments
 (0)