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/Models/Bill.php (2 issues)

Labels
Severity
1
<?php
2
/**
3
 * Bill.php
4
 * Copyright (c) 2017 [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
declare(strict_types=1);
22
23
namespace FireflyIII\Models;
24
25
use Crypt;
26
use Illuminate\Database\Eloquent\Model;
27
use Illuminate\Database\Eloquent\Relations\BelongsTo;
28
use Illuminate\Database\Eloquent\Relations\HasMany;
29
use Illuminate\Database\Eloquent\SoftDeletes;
30
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
31
32
/**
33
 * Class Bill.
34
 */
35
class Bill extends Model
36
{
37
    use SoftDeletes;
38
    /**
39
     * The attributes that should be casted to native types.
40
     *
41
     * @var array
42
     */
43
    protected $casts
44
        = [
45
            'created_at'      => 'datetime',
46
            'updated_at'      => 'datetime',
47
            'deleted_at'      => 'datetime',
48
            'date'            => 'date',
49
            'skip'            => 'int',
50
            'automatch'       => 'boolean',
51
            'active'          => 'boolean',
52
            'name_encrypted'  => 'boolean',
53
            'match_encrypted' => 'boolean',
54
        ];
55
    /**
56
     * @var array
57
     */
58
    protected $fillable
59
        = ['name', 'match', 'amount_min', 'match_encrypted', 'name_encrypted', 'user_id', 'amount_max', 'date', 'repeat_freq', 'skip',
60
           'automatch', 'active',];
61
    /**
62
     * @var array
63
     */
64
    protected $hidden = ['amount_min_encrypted', 'amount_max_encrypted', 'name_encrypted', 'match_encrypted'];
65
66
    /**
67
     * @param string $value
68
     *
69
     * @return Bill
70
     * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
71
     */
72
    public static function routeBinder(string $value): Bill
73
    {
74
        if (auth()->check()) {
75
            $billId = (int)$value;
76
            $bill   = auth()->user()->bills()->find($billId);
77
            if (null !== $bill) {
78
                return $bill;
79
            }
80
        }
81
        throw new NotFoundHttpException;
82
    }
83
84
    /**
85
     * @codeCoverageIgnore
86
     * @return \Illuminate\Database\Eloquent\Relations\MorphMany
87
     */
88
    public function attachments()
89
    {
90
        return $this->morphMany('FireflyIII\Models\Attachment', 'attachable');
91
    }
92
93
    /**
94
     * @codeCoverageIgnore
95
     *
96
     * @param $value
97
     *
98
     * @return string
99
     * @throws \Illuminate\Contracts\Encryption\DecryptException
100
     */
101
    public function getMatchAttribute($value)
102
    {
103
        if (1 === (int)$this->match_encrypted) {
0 ignored issues
show
The property match_encrypted does not seem to exist on FireflyIII\Models\Bill. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
104
            return Crypt::decrypt($value);
105
        }
106
107
        return $value;
108
    }
109
110
    /**
111
     * @codeCoverageIgnore
112
     *
113
     * @param $value
114
     *
115
     * @return string
116
     * @throws \Illuminate\Contracts\Encryption\DecryptException
117
     */
118
    public function getNameAttribute($value)
119
    {
120
        if (1 === (int)$this->name_encrypted) {
0 ignored issues
show
The property name_encrypted does not seem to exist on FireflyIII\Models\Bill. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
121
            return Crypt::decrypt($value);
122
        }
123
124
        return $value;
125
    }
126
127
    /**
128
     * @codeCoverageIgnore
129
     * Get all of the notes.
130
     */
131
    public function notes()
132
    {
133
        return $this->morphMany(Note::class, 'noteable');
134
    }
135
136
    /**
137
     * @codeCoverageIgnore
138
     *
139
     * @param $value
140
     */
141
    public function setAmountMaxAttribute($value)
142
    {
143
        $this->attributes['amount_max'] = (string)$value;
144
    }
145
146
    /**
147
     * @param $value
148
     *
149
     * @codeCoverageIgnore
150
     */
151
    public function setAmountMinAttribute($value)
152
    {
153
        $this->attributes['amount_min'] = (string)$value;
154
    }
155
156
    /**
157
     * @param $value
158
     *
159
     * @codeCoverageIgnore
160
     * @throws \Illuminate\Contracts\Encryption\EncryptException
161
     */
162
    public function setMatchAttribute($value)
163
    {
164
        $encrypt                             = config('firefly.encryption');
165
        $this->attributes['match']           = $encrypt ? Crypt::encrypt($value) : $value;
166
        $this->attributes['match_encrypted'] = $encrypt;
167
    }
168
169
    /**
170
     * @param $value
171
     *
172
     * @codeCoverageIgnore
173
     * @throws \Illuminate\Contracts\Encryption\EncryptException
174
     */
175
    public function setNameAttribute($value)
176
    {
177
        $encrypt                            = config('firefly.encryption');
178
        $this->attributes['name']           = $encrypt ? Crypt::encrypt($value) : $value;
179
        $this->attributes['name_encrypted'] = $encrypt;
180
    }
181
182
    /**
183
     * @codeCoverageIgnore
184
     * @return HasMany
185
     */
186
    public function transactionJournals(): HasMany
187
    {
188
        return $this->hasMany('FireflyIII\Models\TransactionJournal');
189
    }
190
191
    /**
192
     * @codeCoverageIgnore
193
     * @return BelongsTo
194
     */
195
    public function user(): BelongsTo
196
    {
197
        return $this->belongsTo('FireflyIII\User');
198
    }
199
}
200