Skip to content

Commit 0ea0b56

Browse files
committed
code reformat
support for unstored records
1 parent b3da75c commit 0ea0b56

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

src/SpojeNet/Cnb/ExchangeRate.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public function storeDay(int $dayBack = 0): void {
103103
if ($this->insertToSQL($currencyData)) {
104104
$this->addStatusMessage(sprintf(_('Stored: %s for %s'), $currencyData['code'], $currencyData['date']), 'success');
105105
}
106+
} else {
107+
$this->addStatusMessage(sprintf(_('Already present: %s for %s'), $currencyData['code'], $currencyData['date']), 'warning');
106108
}
107109
}
108110
}
@@ -119,7 +121,17 @@ public function shiftDays(): void {
119121
}
120122

121123
public function getRateInfo($currency, $age): array {
122-
return $this->getColumnsFromSQL(['*'], ['code' => $currency, 'date' => self::dateBeforeDays($age)]);
124+
125+
$rateInfo = $this->getColumnsFromSQL(['*'], ['code' => $currency, 'date' => self::dateBeforeDays($age)]);
126+
127+
if($rateInfo){
128+
$result = $rateInfo;
129+
} else {
130+
$result['message'] = 'no record for '. self::dateBeforeDays($age)];
131+
}
132+
133+
$result['age'] = $age;
134+
return $result ;
123135
}
124136

125137
public static function dateBeforeDays(int $daysBack): string {

src/index.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@
3434
break;
3535
case 'beforeyesterday':
3636
$age = 2;
37+
3738
break;
39+
3840
default:
3941
$age = isset($_GET['age']) ? (int) $_GET['age'] : 0;
40-
42+
4143
break;
4244
}
4345

@@ -48,12 +50,14 @@
4850
echo '<html><head><title>CNB Cache</title></head><body>';
4951
echo '<img src="cnb-cache.svg" style="width: 100px;" align="right">';
5052
echo '<ul>';
53+
5154
foreach ($currencyList as $currency) {
52-
echo '<li><strong><a href="?currency='.$currency.'">' . $currency . '</a></strong>&nbsp;';
55+
echo '<li><strong><a href="?currency='.$currency.'">'.$currency.'</a></strong>&nbsp;';
5356
echo '<a href="?currency='.$currency.'&when=yesterday">yesterday</a>&nbsp;';
5457
echo '<small><a href="?currency='.$currency.'&when=beforeyesterday">beforeyesterday</a></small>';
5558
echo '</li>';
5659
}
60+
5761
echo '</ul>';
5862
echo '</body></html>';
5963

src/init.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@
1212
* For the full copyright and license information, please view the LICENSE
1313
* file that was distributed with this source code.
1414
*/
15+
1516
use Ease\Shared;
1617

1718
require_once '../vendor/autoload.php';
1819

19-
define('APP_NAME', 'CNB Cache Init');
20+
\define('APP_NAME', 'CNB Cache Init');
2021

2122
$options = getopt('e::', ['environment::']);
2223

2324
Shared::init(
24-
['CURRENCIES', 'DB_CONNECTION', 'DB_HOST', 'DB_PORT', 'DB_DATABASE', 'DB_USERNAME', 'DB_PASSWORD'],
25-
\array_key_exists('environment', $options) ? $options['environment'] : (\array_key_exists('e', $options) ? $options['e'] : '../.env'),
25+
['CURRENCIES', 'DB_CONNECTION', 'DB_HOST', 'DB_PORT', 'DB_DATABASE', 'DB_USERNAME', 'DB_PASSWORD'],
26+
\array_key_exists('environment', $options) ? $options['environment'] : (\array_key_exists('e', $options) ? $options['e'] : '../.env'),
2627
);
2728

2829
$engine = new \SpojeNet\Cnb\ExchangeRate();
@@ -32,8 +33,7 @@
3233
}
3334

3435
$keepDdays = $engine->getKeepDays();
35-
for($i = 0; $i < $keepDdays; $i++) {
36+
37+
for ($i = 0; $i < $keepDdays; ++$i) {
3638
$engine->storeDay($i);
3739
}
38-
39-

src/update.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
);
2828

2929
$engine = new \SpojeNet\Cnb\ExchangeRate();
30+
3031
if (\Ease\Shared::cfg('APP_DEBUG')) {
3132
$engine->logBanner();
3233
}

0 commit comments

Comments
 (0)