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 ( 6f8b1f...142a48 )
by James
25:51 queued 11:45
created

JournalAPIRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 6
eloc 16
c 1
b 1
f 0
dl 0
loc 70
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getPiggyBankEvents() 0 11 1
A __construct() 0 4 2
A findTransaction() 0 8 1
A setUser() 0 3 1
A getAttachments() 0 3 1
1
<?php
2
/**
3
 * JournalAPIRepository.php
4
 * Copyright (c) 2019 [email protected]
5
 *
6
 * This file is part of Firefly III.
7
 *
8
 * Firefly III is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * Firefly III 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 General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
namespace FireflyIII\Repositories\Journal;
23
24
use FireflyIII\Models\PiggyBankEvent;
25
use FireflyIII\Models\Transaction;
26
use FireflyIII\Models\TransactionJournal;
27
use FireflyIII\User;
28
use Illuminate\Support\Collection;
29
use Log;
30
31
/**
32
 * Class JournalAPIRepository
33
 */
34
class JournalAPIRepository implements JournalAPIRepositoryInterface
35
{
36
    /** @var User */
37
    private $user;
38
39
    /**
40
     * Constructor.
41
     */
42
    public function __construct()
43
    {
44
        if ('testing' === config('app.env')) {
45
            Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
46
        }
47
    }
48
49
    /**
50
     * Returns transaction by ID. Used to validate attachments.
51
     *
52
     * @param int $transactionId
53
     *
54
     * @return Transaction|null
55
     */
56
    public function findTransaction(int $transactionId): ?Transaction
57
    {
58
        $transaction = Transaction::leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
59
                                  ->where('transaction_journals.user_id', $this->user->id)
60
                                  ->where('transactions.id', $transactionId)
61
                                  ->first(['transactions.*']);
62
63
        return $transaction;
64
    }
65
66
    /**
67
     * Return all attachments for journal.
68
     *
69
     * @param TransactionJournal $journal
70
     *
71
     * @return Collection
72
     */
73
    public function getAttachments(TransactionJournal $journal): Collection
74
    {
75
        return $journal->attachments;
76
    }
77
78
    /**
79
     * Get all piggy bank events for a journal.
80
     *
81
     * @param TransactionJournal $journal
82
     *
83
     * @return Collection
84
     */
85
    public function getPiggyBankEvents(TransactionJournal $journal): Collection
86
    {
87
        /** @var Collection $set */
88
        $events = $journal->piggyBankEvents()->get();
89
        $events->each(
90
            function (PiggyBankEvent $event) {
91
                $event->piggyBank = $event->piggyBank()->withTrashed()->first();
92
            }
93
        );
94
95
        return $events;
96
    }
97
98
    /**
99
     * @param User $user
100
     */
101
    public function setUser(User $user): void
102
    {
103
        $this->user = $user;
104
    }
105
}