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/Preference.php (1 issue)

Severity
1
<?php
2
/**
3
 * Preference.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 Exception;
27
use FireflyIII\Exceptions\FireflyException;
28
use Illuminate\Contracts\Encryption\DecryptException;
29
use Illuminate\Database\Eloquent\Model;
30
use Log;
31
32
/**
33
 * Class Preference.
34
 *
35
 * @property mixed $data
36
 */
37
class Preference extends Model
38
{
39
    /**
40
     * The attributes that should be casted to native types.
41
     *
42
     * @var array
43
     */
44
    protected $casts
45
        = [
46
            'created_at' => 'datetime',
47
            'updated_at' => 'datetime',
48
        ];
49
50
    /** @var array */
51
    protected $fillable = ['user_id', 'data', 'name', 'data'];
52
53
    /**
54
     * @param $value
55
     *
56
     * @return mixed
57
     *
58
     * @throws FireflyException
59
     */
60
    public function getDataAttribute($value)
61
    {
62
        try {
63
            $data = Crypt::decrypt($value);
64
        } catch (DecryptException $e) {
65
            Log::error('Could not decrypt preference.', ['id' => $this->id, 'name' => $this->name, 'data' => $value]);
66
            throw new FireflyException(
67
                sprintf('Could not decrypt preference #%d. If this error persists, please run "php artisan cache:clear" on the command line.', $this->id)
68
            );
69
        }
70
        $unserialized = false;
0 ignored issues
show
The assignment to $unserialized is dead and can be removed.
Loading history...
71
        try {
72
            $unserialized = unserialize($data);
73
        } catch (Exception $e) {
74
            // don't care, assume is false.
75
        }
76
        if (!(false === $unserialized)) {
77
            return $unserialized;
78
        }
79
80
        return json_decode($data, true);
81
    }
82
83
    /**
84
     * @codeCoverageIgnore
85
     *
86
     * @param $value
87
     *
88
     * @throws \Illuminate\Contracts\Encryption\EncryptException
89
     */
90
    public function setDataAttribute($value)
91
    {
92
        $this->attributes['data'] = Crypt::encrypt(serialize($value));
93
    }
94
95
    /**
96
     * @codeCoverageIgnore
97
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
98
     */
99
    public function user()
100
    {
101
        return $this->belongsTo('FireflyIII\User');
102
    }
103
}
104