GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 37b02e...ebbbe1 )
by James
08:59
created

app/Export/Entry/Entry.php (2 issues)

Labels
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Entry.php
5
 * Copyright (c) 2017 [email protected]
6
 *
7
 * This file is part of Firefly III.
8
 *
9
 * Firefly III is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation, either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * Firefly III is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
namespace FireflyIII\Export\Entry;
24
25
use FireflyIII\Models\Transaction;
26
27
/**
28
 * To extend the exported object, in case of new features in Firefly III for example,
29
 * do the following:.
30
 *
31
 * - Add the field(s) to this class. If you add more than one related field, add a new object.
32
 * - Make sure the "fromJournal"-routine fills these fields.
33
 * - Add them to the static function that returns its type (key=value. Remember that the only
34
 *   valid types can be found in config/csv.php (under "roles").
35
 *
36
 * These new entries should be should be strings and numbers as much as possible.
37
 *
38
 *
39
 *
40
 * Class Entry
41
 *
42
 * @SuppressWarnings(PHPMD.LongVariable)
43
 * @SuppressWarnings(PHPMD.TooManyFields)
44
 */
45
final class Entry
46
{
47
    // @formatter:off
48
    /**
49
     * @var int
50
     */
51
    public $journal_id;
52
    /**
53
     * @var int
54
     */
55
    public $transaction_id = 0;
56
57
    /**
58
     * @var string
59
     */
60
    public $date;
61
    /**
62
     * @var string
63
     */
64
    public $description;
65
66
    /**
67
     * @var string
68
     */
69
    public $currency_code;
70
    /**
71
     * @var string
72
     */
73
    public $amount;
74
    /**
75
     * @var string
76
     */
77
    public $foreign_currency_code = '';
78
    /**
79
     * @var string
80
     */
81
    public $foreign_amount = '0';
82
83
    /**
84
     * @var string
85
     */
86
    public $transaction_type;
87
88
    /**
89
     * @var string
90
     */
91
    public $asset_account_id;
92
    /**
93
     * @var string
94
     */
95
    public $asset_account_name;
96
    /**
97
     * @var string
98
     */
99
    public $asset_account_iban;
100
    /**
101
     * @var string
102
     */
103
    public $asset_account_bic;
104
    /**
105
     * @var string
106
     */
107
    public $asset_account_number;
108
    /**
109
     * @var string
110
     */
111
    public $asset_currency_code;
112
113
    /**
114
     * @var string
115
     */
116
    public $opposing_account_id;
117
    /**
118
     * @var string
119
     */
120
    public $opposing_account_name;
121
    /**
122
     * @var string
123
     */
124
    public $opposing_account_iban;
125
    /**
126
     * @var string
127
     */
128
    public $opposing_account_bic;
129
    /**
130
     * @var string
131
     */
132
    public $opposing_account_number;
133
    /**
134
     * @var string
135
     */
136
    public $opposing_currency_code;
137
138
    /**
139
     * @var string
140
     */
141
    public $budget_id;
142
    /**
143
     * @var string
144
     */
145
    public $budget_name;
146
147
    /**
148
     * @var string
149
     */
150
    public $category_id;
151
    /**
152
     * @var string
153
     */
154
    public $category_name;
155
156
    /**
157
     * @var string
158
     */
159
    public $bill_id;
160
    /**
161
     * @var string
162
     */
163
    public $bill_name;
164
165
    /**
166
     * @var string
167
     */
168
    public $notes;
169
170
    /**
171
     * @var string
172
     */
173
    public $tags;
174
175
176
    // @formatter:on
177
178
    /**
179
     * Entry constructor.
180
     */
181
    private function __construct()
182
    {
183
    }
184
185
    /**
186
     * Converts a given transaction (as collected by the collector) into an export entry.
187
     *
188
     * @SuppressWarnings(PHPMD.CyclomaticComplexity) // complex but little choice.
189
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength) // cannot be helped
190
     *
191
     * @param Transaction $transaction
192
     *
193
     * @return Entry
194
     */
195
    public static function fromTransaction(Transaction $transaction): Entry
196
    {
197
        $entry                 = new self();
198
        $entry->journal_id     = $transaction->journal_id;
199
        $entry->transaction_id = $transaction->id;
200
        $entry->date           = $transaction->date->format('Ymd');
201
        $entry->description    = $transaction->description;
202
        if (strlen((string)$transaction->transaction_description) > 0) {
203
            $entry->description = $transaction->transaction_description . '(' . $transaction->description . ')';
204
        }
205
        $entry->currency_code = $transaction->transactionCurrency->code;
206
        $entry->amount        = (string)round($transaction->transaction_amount, $transaction->transactionCurrency->decimal_places);
0 ignored issues
show
$transaction->transaction_amount of type string is incompatible with the type double expected by parameter $val of round(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

206
        $entry->amount        = (string)round(/** @scrutinizer ignore-type */ $transaction->transaction_amount, $transaction->transactionCurrency->decimal_places);
Loading history...
207
208
        $entry->foreign_currency_code = null === $transaction->foreign_currency_id ? null : $transaction->foreignCurrency->code;
209
        $entry->foreign_amount        = null === $transaction->foreign_currency_id
210
            ? null
211
            : (string)round(
212
                $transaction->transaction_foreign_amount,
213
                $transaction->foreignCurrency->decimal_places
214
            );
215
216
        $entry->transaction_type     = $transaction->transaction_type_type;
217
        $entry->asset_account_id     = (string)$transaction->account_id;
218
        $entry->asset_account_name   = app('steam')->tryDecrypt($transaction->account_name);
0 ignored issues
show
The method tryDecrypt() does not exist on FireflyIII\Support\Facades\Steam. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

218
        $entry->asset_account_name   = app('steam')->/** @scrutinizer ignore-call */ tryDecrypt($transaction->account_name);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
219
        $entry->asset_account_iban   = $transaction->account_iban;
220
        $entry->asset_account_number = $transaction->account_number;
221
        $entry->asset_account_bic    = $transaction->account_bic;
222
        $entry->asset_currency_code  = $transaction->account_currency_code;
223
224
        $entry->opposing_account_id     = (string)$transaction->opposing_account_id;
225
        $entry->opposing_account_name   = app('steam')->tryDecrypt($transaction->opposing_account_name);
226
        $entry->opposing_account_iban   = $transaction->opposing_account_iban;
227
        $entry->opposing_account_number = $transaction->opposing_account_number;
228
        $entry->opposing_account_bic    = $transaction->opposing_account_bic;
229
        $entry->opposing_currency_code  = $transaction->opposing_currency_code;
230
231
        // budget
232
        $entry->budget_id   = (string)$transaction->transaction_budget_id;
233
        $entry->budget_name = app('steam')->tryDecrypt($transaction->transaction_budget_name);
234
        if (null === $transaction->transaction_budget_id) {
235
            $entry->budget_id   = $transaction->transaction_journal_budget_id;
236
            $entry->budget_name = app('steam')->tryDecrypt($transaction->transaction_journal_budget_name);
237
        }
238
239
        // category
240
        $entry->category_id   = (string)$transaction->transaction_category_id;
241
        $entry->category_name = app('steam')->tryDecrypt($transaction->transaction_category_name);
242
        if (null === $transaction->transaction_category_id) {
243
            $entry->category_id   = $transaction->transaction_journal_category_id;
244
            $entry->category_name = app('steam')->tryDecrypt($transaction->transaction_journal_category_name);
245
        }
246
247
        // budget
248
        $entry->bill_id   = (string)$transaction->bill_id;
249
        $entry->bill_name = app('steam')->tryDecrypt($transaction->bill_name);
250
251
        $entry->tags  = $transaction->tags;
252
        $entry->notes = $transaction->notes;
253
254
        return $entry;
255
    }
256
}
257