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.

Issues (724)

JobConfiguration/FinTS/ChooseAccountHandler.php (1 issue)

1
<?php
2
/**
3
 * ChooseAccountHandler.php
4
 * Copyright (c) 2019 https://github.com/bnw
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\Support\Import\JobConfiguration\FinTS;
24
25
26
use Carbon\Carbon;
27
use FireflyIII\Exceptions\FireflyException;
28
use FireflyIII\Import\JobConfiguration\FinTSConfigurationSteps;
29
use FireflyIII\Models\AccountType;
30
use FireflyIII\Models\ImportJob;
31
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
32
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
33
use FireflyIII\Support\FinTS\FinTS;
34
use Illuminate\Support\MessageBag;
35
36
/**
37
 * Class ChooseAccountHandler
38
 *
39
 * @codeCoverageIgnore
40
 * @deprecated
41
 */
42
class ChooseAccountHandler implements FinTSConfigurationInterface
0 ignored issues
show
Deprecated Code introduced by
The interface FireflyIII\Support\Impor...SConfigurationInterface has been deprecated. ( Ignorable by Annotation )

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

42
class ChooseAccountHandler implements /** @scrutinizer ignore-deprecated */ FinTSConfigurationInterface

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.

Loading history...
43
{
44
    /** @var AccountRepositoryInterface */
45
    private $accountRepository;
46
    /** @var ImportJob */
47
    private $importJob;
48
    /** @var ImportJobRepositoryInterface */
49
    private $repository;
50
51
    /**
52
     * Store data associated with current stage.
53
     *
54
     * @param array $data
55
     *
56
     * @return MessageBag
57
     */
58
    public function configureJob(array $data): MessageBag
59
    {
60
        $config                  = $this->repository->getConfiguration($this->importJob);
61
        $config['fints_account'] = (string)($data['fints_account'] ?? '');
62
        $config['local_account'] = (string)($data['local_account'] ?? '');
63
        $config['from_date']     = (string)($data['from_date'] ?? '');
64
        $config['to_date']       = (string)($data['to_date'] ?? '');
65
        $this->repository->setConfiguration($this->importJob, $config);
66
67
        try {
68
            $finTS = app(FinTS::class, ['config' => $config]);
69
            $finTS->getAccount($config['fints_account']);
70
        } catch (FireflyException $e) {
71
            return new MessageBag([$e->getMessage()]);
72
        }
73
74
        $this->repository->setStage($this->importJob, FinTSConfigurationSteps::GO_FOR_IMPORT);
75
76
        return new MessageBag();
77
    }
78
79
    /**
80
     * Get the data necessary to show the configuration screen.
81
     *
82
     * @return array
83
     */
84
    public function getNextData(): array
85
    {
86
        $finTS             = app(FinTS::class, ['config' => $this->importJob->configuration]);
87
        $finTSAccounts     = $finTS->getAccounts();
88
        $finTSAccountsData = [];
89
        foreach ($finTSAccounts as $account) {
90
            $finTSAccountsData[$account->getAccountNumber()] = $account->getIban();
91
        }
92
93
        $localAccounts = [];
94
        foreach ($this->accountRepository->getAccountsByType([AccountType::ASSET]) as $localAccount) {
95
            $display_name = $localAccount->name;
96
            if ($localAccount->iban) {
97
                $display_name .= sprintf(' - %s', $localAccount->iban);
98
            }
99
            $localAccounts[$localAccount->id] = $display_name;
100
        }
101
102
        $data = [
103
            'fints_accounts' => $finTSAccountsData,
104
            'fints_account'  => $this->importJob->configuration['fints_account'] ?? null,
105
            'local_accounts' => $localAccounts,
106
            'local_account'  => $this->importJob->configuration['local_account'] ?? null,
107
            'from_date'      => $this->importJob->configuration['from_date'] ?? (new Carbon('now - 1 month'))->format('Y-m-d'),
108
            'to_date'        => $this->importJob->configuration['to_date'] ?? (new Carbon('now'))->format('Y-m-d'),
109
        ];
110
111
        return $data;
112
    }
113
114
    /**
115
     * @param ImportJob $importJob
116
     */
117
    public function setImportJob(ImportJob $importJob): void
118
    {
119
        $this->importJob         = $importJob;
120
        $this->repository        = app(ImportJobRepositoryInterface::class);
121
        $this->accountRepository = app(AccountRepositoryInterface::class);
122
        $this->repository->setUser($importJob->user);
123
    }
124
}
125