Skip to content

Commit 648f9df

Browse files
author
Vítězslav Dvořák
committed
Refactor Statementor class: add datescope trait, remove unused methods, and update account fetching logic
1 parent 52feeca commit 648f9df

File tree

4 files changed

+15
-258
lines changed

4 files changed

+15
-258
lines changed

.openapi-generator/templates/Statementor.mustache

Lines changed: 3 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ namespace SpojeNet\CSas;
2525
class Statementor extends \Ease\Sand
2626
{
2727
use \Ease\Logger\Logging;
28+
use \Ease\datescope;
29+
2830
public \DateTime $since;
2931
public \DateTime $until;
3032
public string $currency = 'CZK';
@@ -99,112 +101,8 @@ class Statementor extends \Ease\Sand
99101
return $statements;
100102
}
101103

102-
/**
103-
* Prepare processing interval.
104-
*
105-
* @param mixed $scope
106-
*
107-
* @throws \Exception
108-
*/
109-
public function setScope($scope): \DatePeriod
110-
{
111-
switch ($scope) {
112-
case 'yesterday':
113-
$this->since = (new \DateTime('yesterday'))->setTime(0, 0);
114-
$this->until = (new \DateTime('yesterday'))->setTime(23, 59);
115-
116-
break;
117-
case 'current_month':
118-
$this->since = new \DateTime('first day of this month');
119-
$this->until = new \DateTime();
120-
121-
break;
122-
case 'last_month':
123-
$this->since = new \DateTime('first day of last month');
124-
$this->until = new \DateTime('last day of last month');
125-
126-
break;
127-
case 'last_week':
128-
$this->since = new \DateTime('first day of last week');
129-
$this->until = new \DateTime('last day of last week');
130-
131-
break;
132-
case 'last_two_months':
133-
$this->since = (new \DateTime('first day of last month'))->modify('-1 month');
134-
$this->until = (new \DateTime('last day of last month'));
135-
136-
break;
137-
case 'previous_month':
138-
$this->since = new \DateTime('first day of -2 month');
139-
$this->until = new \DateTime('last day of -2 month');
140-
141-
break;
142-
case 'two_months_ago':
143-
$this->since = new \DateTime('first day of -3 month');
144-
$this->until = new \DateTime('last day of -3 month');
145-
146-
break;
147-
case 'this_year':
148-
$this->since = new \DateTime('first day of January '.date('Y'));
149-
$this->until = new \DateTime('last day of December'.date('Y'));
150-
151-
break;
152-
case 'January': // 1
153-
case 'February': // 2
154-
case 'March': // 3
155-
case 'April': // 4
156-
case 'May': // 5
157-
case 'June': // 6
158-
case 'July': // 7
159-
case 'August': // 8
160-
case 'September':// 9
161-
case 'October': // 10
162-
case 'November': // 11
163-
case 'December': // 12
164-
$this->since = new \DateTime('first day of '.$scope.' '.date('Y'));
165-
$this->until = new \DateTime('last day of '.$scope.' '.date('Y'));
166-
167-
break;
168-
case 'auto':
169-
$latestRecord = $this->getColumnsFromPohoda(['id', 'lastUpdate'], ['limit' => 1, 'order' => 'lastUpdate@A', 'source' => $this->sourceString(), 'banka' => $this->bank]);
170-
171-
if (\array_key_exists(0, $latestRecord) && \array_key_exists('lastUpdate', $latestRecord[0])) {
172-
$this->since = $latestRecord[0]['lastUpdate'];
173-
} else {
174-
$this->addStatusMessage('Previous record for "auto since" not found. Defaulting to today\'s 00:00', 'warning');
175-
$this->since = (new \DateTime())->setTime(0, 0);
176-
}
177-
178-
$this->until = new \DateTime(); // Now
179104

180-
break;
181105

182-
default:
183-
if (strstr($scope, '>')) {
184-
[$begin, $end] = explode('>', $scope);
185-
$this->since = new \DateTime($begin);
186-
$this->until = new \DateTime($end);
187-
} else {
188-
if (preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $scope)) {
189-
$this->since = new \DateTime($scope);
190-
$this->until = (new \DateTime($scope))->setTime(23, 59, 59, 999);
191-
}
192-
193-
throw new \InvalidArgumentException('Unknown scope '.$scope);
194-
}
195-
196-
break;
197-
}
198-
199-
if ($scope !== 'auto' && $scope !== 'today' && $scope !== 'yesterday') {
200-
$this->since = $this->since->setTime(0, 0);
201-
$this->until = $this->until->setTime(23, 59, 59, 999);
202-
}
203-
204-
$this->scope = $scope;
205-
206-
return $this->getScope();
207-
}
208106

209107
public function getScopeSymbolic(): string
210108
{
@@ -259,22 +157,6 @@ class Statementor extends \Ease\Sand
259157
return $saved;
260158
}
261159

262-
/**
263-
* Since time getter.
264-
*/
265-
public function getSince(): \DateTime
266-
{
267-
return $this->since;
268-
}
269-
270-
/**
271-
* Until time getter.
272-
*/
273-
public function getUntil(): \DateTime
274-
{
275-
return $this->until;
276-
}
277-
278160
public function getAccountNumber(): string
279161
{
280162
return $this->accountNumber;
@@ -351,7 +233,7 @@ class Statementor extends \Ease\Sand
351233
352234
if (isset($accountsRaw) && \is_array($accountsRaw)) {
353235
foreach ($accountsRaw as $account) {
354-
if ($account->getIdentification()->getId() === $uuid) {
236+
if ($account->getId() === $uuid) {
355237
break;
356238
}
357239
}
@@ -360,5 +242,4 @@ class Statementor extends \Ease\Sand
360242
return $account;
361243
}
362244

363-
364245
}

.openapi-generator/templates/composer.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@
3232
"ext-curl": "*",
3333
"ext-json": "*",
3434
"ext-mbstring": "*",
35-
"guzzlehttp/guzzle": "^7.3",
35+
"guzzlehttp/guzzle": "^7.9",
3636
"guzzlehttp/psr7": "^1.7 || ^2.0",
37-
"vitexsoftware/ease-core": "^1.47"
37+
"vitexsoftware/ease-core": "^1.48"
3838
},
3939
"require-dev": {
4040
"phpunit/phpunit": "*",
4141
"phpstan/phpstan": "*",
42-
"friendsofphp/php-cs-fixer": "^3.61",
43-
"ergebnis/composer-normalize": "^2.43",
44-
"ergebnis/php-cs-fixer-config": "^6.34",
42+
"friendsofphp/php-cs-fixer": "^3.84",
43+
"ergebnis/composer-normalize": "^2.47",
44+
"ergebnis/php-cs-fixer-config": "^6.50",
4545
"phpstan/phpstan-phpunit": "^2.0"
4646
},
4747
"autoload": {

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@
2727
"ext-curl": "*",
2828
"ext-json": "*",
2929
"ext-mbstring": "*",
30-
"guzzlehttp/guzzle": "^7.3",
30+
"guzzlehttp/guzzle": "^7.9",
3131
"guzzlehttp/psr7": "^1.7 || ^2.0",
32-
"vitexsoftware/ease-core": "^1.47"
32+
"vitexsoftware/ease-core": "^1.48"
3333
},
3434
"require-dev": {
3535
"phpunit/phpunit": "*",
3636
"phpstan/phpstan": "*",
37-
"friendsofphp/php-cs-fixer": "^3.82",
38-
"ergebnis/composer-normalize": "^2.43",
39-
"ergebnis/php-cs-fixer-config": "^6.34",
37+
"friendsofphp/php-cs-fixer": "^3.84",
38+
"ergebnis/composer-normalize": "^2.47",
39+
"ergebnis/php-cs-fixer-config": "^6.50",
4040
"phpstan/phpstan-phpunit": "^2.0"
4141
},
4242
"autoload": {

lib/Statementor.php

Lines changed: 2 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
class Statementor extends \Ease\Sand
2626
{
2727
use \Ease\Logger\Logging;
28+
use \Ease\datescope;
2829
public \DateTime $since;
2930
public \DateTime $until;
3031
public string $currency = 'CZK';
@@ -99,113 +100,6 @@ public function getStatements($format = 'pdf'): array
99100
return $statements;
100101
}
101102

102-
/**
103-
* Prepare processing interval.
104-
*
105-
* @param mixed $scope
106-
*
107-
* @throws \Exception
108-
*/
109-
public function setScope($scope): \DatePeriod
110-
{
111-
switch ($scope) {
112-
case 'yesterday':
113-
$this->since = (new \DateTime('yesterday'))->setTime(0, 0);
114-
$this->until = (new \DateTime('yesterday'))->setTime(23, 59);
115-
116-
break;
117-
case 'current_month':
118-
$this->since = new \DateTime('first day of this month');
119-
$this->until = new \DateTime();
120-
121-
break;
122-
case 'last_month':
123-
$this->since = new \DateTime('first day of last month');
124-
$this->until = new \DateTime('last day of last month');
125-
126-
break;
127-
case 'last_week':
128-
$this->since = new \DateTime('first day of last week');
129-
$this->until = new \DateTime('last day of last week');
130-
131-
break;
132-
case 'last_two_months':
133-
$this->since = (new \DateTime('first day of last month'))->modify('-1 month');
134-
$this->until = (new \DateTime('last day of last month'));
135-
136-
break;
137-
case 'previous_month':
138-
$this->since = new \DateTime('first day of -2 month');
139-
$this->until = new \DateTime('last day of -2 month');
140-
141-
break;
142-
case 'two_months_ago':
143-
$this->since = new \DateTime('first day of -3 month');
144-
$this->until = new \DateTime('last day of -3 month');
145-
146-
break;
147-
case 'this_year':
148-
$this->since = new \DateTime('first day of January '.date('Y'));
149-
$this->until = new \DateTime('last day of December'.date('Y'));
150-
151-
break;
152-
case 'January': // 1
153-
case 'February': // 2
154-
case 'March': // 3
155-
case 'April': // 4
156-
case 'May': // 5
157-
case 'June': // 6
158-
case 'July': // 7
159-
case 'August': // 8
160-
case 'September':// 9
161-
case 'October': // 10
162-
case 'November': // 11
163-
case 'December': // 12
164-
$this->since = new \DateTime('first day of '.$scope.' '.date('Y'));
165-
$this->until = new \DateTime('last day of '.$scope.' '.date('Y'));
166-
167-
break;
168-
case 'auto':
169-
$latestRecord = $this->getColumnsFromPohoda(['id', 'lastUpdate'], ['limit' => 1, 'order' => 'lastUpdate@A', 'source' => $this->sourceString(), 'banka' => $this->bank]);
170-
171-
if (\array_key_exists(0, $latestRecord) && \array_key_exists('lastUpdate', $latestRecord[0])) {
172-
$this->since = $latestRecord[0]['lastUpdate'];
173-
} else {
174-
$this->addStatusMessage('Previous record for "auto since" not found. Defaulting to today\'s 00:00', 'warning');
175-
$this->since = (new \DateTime())->setTime(0, 0);
176-
}
177-
178-
$this->until = new \DateTime(); // Now
179-
180-
break;
181-
182-
default:
183-
if (strstr($scope, '>')) {
184-
[$begin, $end] = explode('>', $scope);
185-
$this->since = new \DateTime($begin);
186-
$this->until = new \DateTime($end);
187-
} else {
188-
if (preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $scope)) {
189-
$this->since = new \DateTime($scope);
190-
$this->until = (new \DateTime($scope))->setTime(23, 59, 59, 999);
191-
}
192-
193-
throw new \InvalidArgumentException('Unknown scope '.$scope);
194-
}
195-
196-
break;
197-
}
198-
199-
if ($scope !== 'auto' && $scope !== 'today' && $scope !== 'yesterday') {
200-
$this->since = $this->since->setTime(0, 0);
201-
$this->until = $this->until->setTime(23, 59, 59, 999);
202-
}
203-
204-
$this->scope = $scope;
205-
206-
return $this->getScope();
207-
}
208-
209103
public function getScopeSymbolic(): string
210104
{
211105
return $this->scope;
@@ -259,22 +153,6 @@ public function download(string $saveTo, array $statements, string $format = 'pd
259153
return $saved;
260154
}
261155

262-
/**
263-
* Since time getter.
264-
*/
265-
public function getSince(): \DateTime
266-
{
267-
return $this->since;
268-
}
269-
270-
/**
271-
* Until time getter.
272-
*/
273-
public function getUntil(): \DateTime
274-
{
275-
return $this->until;
276-
}
277-
278156
public function getAccountNumber(): string
279157
{
280158
return $this->accountNumber;
@@ -351,14 +229,12 @@ public static function getAccountById(Accounts\DefaultApi $apiInstance, string $
351229

352230
if (isset($accountsRaw) && \is_array($accountsRaw)) {
353231
foreach ($accountsRaw as $account) {
354-
if ($account->getIdentification()->getId() === $uuid) {
232+
if ($account->getId() === $uuid) {
355233
break;
356234
}
357235
}
358236
}
359237

360238
return $account;
361239
}
362-
363-
364240
}

0 commit comments

Comments
 (0)