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.

Recurrence   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 32
dl 0
loc 113
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A recurrenceMeta() 0 3 1
A transactionCurrency() 0 3 1
A user() 0 3 1
A recurrenceTransactions() 0 3 1
A routeBinder() 0 13 3
A recurrenceRepetitions() 0 3 1
A transactionType() 0 3 1
A notes() 0 3 1
1
<?php
2
/**
3
 * Recurrence.php
4
 * Copyright (c) 2019 [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
22
declare(strict_types=1);
23
24
namespace FireflyIII\Models;
25
26
27
use Eloquent;
28
use FireflyIII\User;
29
use Illuminate\Database\Eloquent\Collection;
30
use Illuminate\Database\Eloquent\Model;
31
use Illuminate\Database\Eloquent\Relations\BelongsTo;
32
use Illuminate\Database\Eloquent\Relations\HasMany;
33
use Illuminate\Database\Eloquent\Relations\MorphMany;
34
use Illuminate\Database\Eloquent\SoftDeletes;
35
use Illuminate\Database\Query\Builder;
36
use Illuminate\Support\Carbon;
37
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
38
39
/**
40
 * Class Recurrence
41
 *
42
 * @property int                                                                     $id
43
 * @property \Carbon\Carbon                                                          $created_at
44
 * @property \Carbon\Carbon                                                          $updated_at
45
 * @property int                                                                     $user_id
46
 * @property int                                                                     $transaction_type_id
47
 * @property int                                                                     $transaction_currency_id
48
 * @property string                                                                  $title
49
 * @property string                         $description
50
 * @property \Carbon\Carbon                 $first_date
51
 * @property \Carbon\Carbon                 $repeat_until
52
 * @property \Carbon\Carbon                 $latest_date
53
 * @property string                         $repetition_type
54
 * @property string                         $repetition_moment
55
 * @property int                            $repetition_skip
56
 * @property int                            $repetitions
57
 * @property bool                           $active
58
 * @property bool                           $apply_rules
59
 * @property User                           $user
60
 * @property \Illuminate\Support\Collection $recurrenceRepetitions
61
 * @property \Illuminate\Support\Collection $recurrenceMeta
62
 * @property \Illuminate\Support\Collection $recurrenceTransactions
63
 * @property TransactionType                $transactionType
64
 * @property Carbon|null                    $deleted_at
65
 * @property-read Collection|Note[]         $notes
66
 * @property-read TransactionCurrency       $transactionCurrency
67
 * @method static bool|null forceDelete()
68
 * @method static \Illuminate\Database\Eloquent\Builder|Recurrence newModelQuery()
69
 * @method static \Illuminate\Database\Eloquent\Builder|Recurrence newQuery()
70
 * @method static Builder|Recurrence onlyTrashed()
71
 * @method static \Illuminate\Database\Eloquent\Builder|Recurrence query()
72
 * @method static bool|null restore()
73
 * @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereActive($value)
74
 * @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereApplyRules($value)
75
 * @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereCreatedAt($value)
76
 * @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereDeletedAt($value)
77
 * @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereDescription($value)
78
 * @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereFirstDate($value)
79
 * @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereId($value)
80
 * @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereLatestDate($value)
81
 * @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereRepeatUntil($value)
82
 * @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereRepetitions($value)
83
 * @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereTitle($value)
84
 * @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereTransactionTypeId($value)
85
 * @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereUpdatedAt($value)
86
 * @method static \Illuminate\Database\Eloquent\Builder|Recurrence whereUserId($value)
87
 * @method static Builder|Recurrence withTrashed()
88
 * @method static Builder|Recurrence withoutTrashed()
89
 * @mixin Eloquent
90
 * @property-read int|null $notes_count
91
 * @property-read int|null $recurrence_meta_count
92
 * @property-read int|null $recurrence_repetitions_count
93
 * @property-read int|null $recurrence_transactions_count
94
 */
95
class Recurrence extends Model
96
{
97
    use SoftDeletes;
98
    /**
99
     * The attributes that should be casted to native types.
100
     *
101
     * @var array
102
     */
103
    protected $casts
104
        = [
105
            'created_at'   => 'datetime',
106
            'updated_at'   => 'datetime',
107
            'deleted_at'   => 'datetime',
108
            'title'        => 'string',
109
            'id'           => 'int',
110
            'description'  => 'string',
111
            'first_date'   => 'date',
112
            'repeat_until' => 'date',
113
            'latest_date'  => 'date',
114
            'repetitions'  => 'int',
115
            'active'       => 'bool',
116
            'apply_rules'  => 'bool',
117
        ];
118
    /** @var array Fields that can be filled */
119
    protected $fillable
120
        = ['user_id', 'transaction_type_id', 'title', 'description', 'first_date', 'repeat_until', 'latest_date', 'repetitions', 'apply_rules', 'active'];
121
    /** @var string The table to store the data in */
122
    protected $table = 'recurrences';
123
124
    /**
125
     * Route binder. Converts the key in the URL to the specified object (or throw 404).
126
     *
127
     * @param string $value
128
     *
129
     * @throws NotFoundHttpException
130
     * @return Recurrence
131
     */
132
    public static function routeBinder(string $value): Recurrence
133
    {
134
        if (auth()->check()) {
135
            $recurrenceId = (int) $value;
136
            /** @var User $user */
137
            $user = auth()->user();
138
            /** @var Recurrence $recurrence */
139
            $recurrence = $user->recurrences()->find($recurrenceId);
140
            if (null !== $recurrence) {
141
                return $recurrence;
142
            }
143
        }
144
        throw new NotFoundHttpException;
145
    }
146
147
    /**
148
     * @codeCoverageIgnore
149
     * Get all of the notes.
150
     */
151
    public function notes(): MorphMany
152
    {
153
        return $this->morphMany(Note::class, 'noteable');
154
    }
155
156
    /**
157
     * @return HasMany
158
     * @codeCoverageIgnore
159
     */
160
    public function recurrenceMeta(): HasMany
161
    {
162
        return $this->hasMany(RecurrenceMeta::class);
163
    }
164
165
    /**
166
     * @return HasMany
167
     * @codeCoverageIgnore
168
     */
169
    public function recurrenceRepetitions(): HasMany
170
    {
171
        return $this->hasMany(RecurrenceRepetition::class);
172
    }
173
174
    /**
175
     * @return HasMany
176
     * @codeCoverageIgnore
177
     */
178
    public function recurrenceTransactions(): HasMany
179
    {
180
        return $this->hasMany(RecurrenceTransaction::class);
181
    }
182
183
    /**
184
     * @codeCoverageIgnore
185
     * @return BelongsTo
186
     */
187
    public function transactionCurrency(): BelongsTo
188
    {
189
        return $this->belongsTo(TransactionCurrency::class);
190
    }
191
192
    /**
193
     * @codeCoverageIgnore
194
     * @return BelongsTo
195
     */
196
    public function transactionType(): BelongsTo
197
    {
198
        return $this->belongsTo(TransactionType::class);
199
    }
200
201
    /**
202
     * @codeCoverageIgnore
203
     * @return BelongsTo
204
     */
205
    public function user(): BelongsTo
206
    {
207
        return $this->belongsTo(User::class);
208
    }
209
210
}
211