|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
* EmptyDescription.php |
|
5
|
|
|
* Copyright (c) 2020 [email protected] |
|
6
|
|
|
* |
|
7
|
|
|
* This file is part of the Firefly III CSV importer |
|
8
|
|
|
* (https://github.com/firefly-iii/csv-importer). |
|
9
|
|
|
* |
|
10
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
11
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
12
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
13
|
|
|
* License, or (at your option) any later version. |
|
14
|
|
|
* |
|
15
|
|
|
* This program is distributed in the hope that it will be useful, |
|
16
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
* GNU Affero General Public License for more details. |
|
19
|
|
|
* |
|
20
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
21
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
namespace App\Services\Import\Task; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Class EmptyDescription |
|
28
|
|
|
*/ |
|
29
|
|
|
class EmptyDescription extends AbstractTask |
|
30
|
|
|
{ |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param array $group |
|
34
|
|
|
* |
|
35
|
|
|
* @return array |
|
36
|
|
|
*/ |
|
37
|
|
|
public function process(array $group): array |
|
38
|
|
|
{ |
|
39
|
|
|
foreach ($group['transactions'] as $index => $transaction) { |
|
40
|
|
|
$group['transactions'][$index] = $this->processDescription($transaction); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
return $group; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Returns true if the task requires the default account. |
|
48
|
|
|
* |
|
49
|
|
|
* @return bool |
|
50
|
|
|
*/ |
|
51
|
|
|
public function requiresDefaultAccount(): bool |
|
52
|
|
|
{ |
|
53
|
|
|
return false; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Returns true if the task requires the default currency of the user. |
|
58
|
|
|
* |
|
59
|
|
|
* @return bool |
|
60
|
|
|
*/ |
|
61
|
|
|
public function requiresTransactionCurrency(): bool |
|
62
|
|
|
{ |
|
63
|
|
|
return true; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param array $transaction |
|
68
|
|
|
* |
|
69
|
|
|
* @return array |
|
70
|
|
|
*/ |
|
71
|
|
|
private function processDescription(array $transaction): array |
|
72
|
|
|
{ |
|
73
|
|
|
$transaction['description'] = $transaction['description'] ?? ''; |
|
74
|
|
|
if ('' === $transaction['description']) { |
|
75
|
|
|
$transaction['description'] = '(empty description)'; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $transaction; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|