1 | <?php |
||
2 | /** |
||
3 | * IngBelgium.php |
||
4 | * Copyright (c) 2019 Sander Kleykens <[email protected]> |
||
5 | * |
||
6 | * This file is part of Firefly III (https://github.com/firefly-iii). |
||
7 | * |
||
8 | * This program is free software: you can redistribute it and/or modify |
||
9 | * it under the terms of the GNU Affero General Public License as |
||
10 | * published by the Free Software Foundation, either version 3 of the |
||
11 | * License, or (at your option) any later version. |
||
12 | * |
||
13 | * This program is distributed in the hope that it will be useful, |
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
16 | * GNU Affero General Public License for more details. |
||
17 | * |
||
18 | * You should have received a copy of the GNU Affero General Public License |
||
19 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
20 | */ |
||
21 | declare(strict_types=1); |
||
22 | |||
23 | namespace FireflyIII\Import\Specifics; |
||
24 | |||
25 | /** |
||
26 | * Class IngBelgium. |
||
27 | * |
||
28 | * @deprecated |
||
29 | * @codeCoverageIgnore |
||
30 | * |
||
31 | * Parses the description and opposing account information (IBAN and name) from CSV files for ING Belgium bank accounts. |
||
32 | * |
||
33 | */ |
||
34 | class IngBelgium implements SpecificInterface |
||
0 ignored issues
–
show
|
|||
35 | { |
||
36 | /** |
||
37 | * Description of the current specific. |
||
38 | * |
||
39 | * @return string |
||
40 | * @codeCoverageIgnore |
||
41 | */ |
||
42 | public static function getDescription(): string |
||
43 | { |
||
44 | return 'import.specific_ingbelgium_descr'; |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Name of the current specific. |
||
49 | * |
||
50 | * @return string |
||
51 | * @codeCoverageIgnore |
||
52 | */ |
||
53 | public static function getName(): string |
||
54 | { |
||
55 | return 'import.specific_ingbelgium_name'; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Gets the description from the transaction details and makes sure structured descriptions are in the |
||
60 | * "+++090/9337/55493+++" format. |
||
61 | * |
||
62 | * @return string the description |
||
63 | */ |
||
64 | protected static function description(string $transactionDetails): string |
||
65 | { |
||
66 | $description = IngBelgium::parseInformationFromTransactionDetails($transactionDetails, '/Mededeling:\s*(.+)$/'); |
||
67 | |||
68 | return IngBelgium::convertStructuredDescriptionToProperFormat($description); |
||
69 | } |
||
70 | |||
71 | /** |
||
72 | * Gets the opposing account's IBAN from the transaction details. |
||
73 | * |
||
74 | * @return string the opposing account's IBAN |
||
75 | */ |
||
76 | protected static function opposingAccountIban(string $transactionDetails): string |
||
77 | { |
||
78 | return IngBelgium::parseInformationFromTransactionDetails($transactionDetails, '/IBAN:\s*(.+?)(?=\s+)/'); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * Gets the opposing account name from the transaction details. |
||
83 | * |
||
84 | * @return string the opposing account name |
||
85 | */ |
||
86 | protected static function opposingAccountName(string $transactionDetails): string |
||
87 | { |
||
88 | return IngBelgium::parseInformationFromTransactionDetails($transactionDetails, '/Van:\s*(.+?)(?=\s{2,})/'); |
||
89 | |||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Gets the description and opposing account information (IBAN and name) from the transaction details and adds |
||
94 | * them to the row of data. |
||
95 | * |
||
96 | * @return array the row containing the description and opposing account's IBAN |
||
97 | */ |
||
98 | protected static function processTransactionDetails(array $row): array |
||
99 | { |
||
100 | if (isset($row[9])) { |
||
101 | $transactionDetails = $row[9]; |
||
102 | $row[11] = IngBelgium::opposingAccountName($transactionDetails); |
||
103 | $row[12] = IngBelgium::opposingAccountIban($transactionDetails); |
||
104 | $row[13] = IngBelgium::description($transactionDetails); |
||
105 | } |
||
106 | |||
107 | return $row; |
||
108 | } |
||
109 | |||
110 | private static function convertStructuredDescriptionToProperFormat(string $description): string |
||
111 | { |
||
112 | preg_match('/^\*\*\*(\d{3}\/\d{4}\/\d{5})\*\*\*$/', $description, $matches); |
||
113 | if (isset($matches[1])) { |
||
114 | return '+++' . $matches[1] . '+++'; |
||
115 | } |
||
116 | |||
117 | return $description; |
||
118 | } |
||
119 | |||
120 | private static function parseInformationFromTransactionDetails(string $transactionDetails, string $regex): string |
||
121 | { |
||
122 | if (isset($transactionDetails)) { |
||
123 | preg_match($regex, $transactionDetails, $matches); |
||
124 | if (isset($matches[1])) { |
||
125 | return trim($matches[1]); |
||
126 | } |
||
127 | } |
||
128 | |||
129 | return ''; |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * Run the specific code. |
||
134 | * |
||
135 | * @param array $row |
||
136 | * |
||
137 | * @return array |
||
138 | * |
||
139 | */ |
||
140 | public function run(array $row): array |
||
141 | { |
||
142 | return IngBelgium::processTransactionDetails($row); |
||
143 | } |
||
144 | } |
||
145 |
This interface has been deprecated. The supplier of the interface has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.