Scrutinizer GitHub App not installed

We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.

Install GitHub App

Completed
Pull Request — development (#51)
by José
04:26
created

User::invites()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace DoeSangue\Models;
4
5
use Illuminate\Notifications\Notifiable;
6
use Illuminate\Foundation\Auth\User as Authenticatable;
7
use Illuminate\Database\Eloquent\SoftDeletes;
8
use DoeSangue\Models\Campaign;
9
use DoeSangue\Models\Invite;
10
use DoeSangue\Models\BloodType;
11
use DoeSangue\Models\Comment;
12
use Webpatser\Uuid\Uuid;
13
14
class User extends Authenticatable
15
{
16
    use Notifiable, SoftDeletes;
17
18
    /**
19
     * The attributes that are mass assignable.
20
     *
21
     * @var array
22
     */
23
    protected $fillable =
24
      [
25
        'first_name',
26
        'last_name',
27
        'email',
28
        'username',
29
        'phone',
30
        'country_code',
31
        'bio',
32
        'birthdate',
33
        'active',
34
        'password',
35
        'blood_type_id',
36
        ];
37
38
    /**
39
     * The attributes that should be hidden for arrays.
40
     *
41
     * @var array
42
     */
43
    protected $hidden =
44
        [
45
          'password',
46
          'remember_token',
47
          'created_at',
48
          'updated_at',
49
          'deleted_at',
50
          'phone',
51
          'active',
52
          'username',
53
          'is_active',
54
          'birthdate',
55
          'email',
56
          'blood_type_id'
57
        ];
58
59
      /**
60
       * Indicates if the IDs are auto-incrementing.
61
       *
62
       * @var bool
63
       */
64
    public $incrementing = false;
65
66
    /**
67
     * The dates attributes.
68
     *
69
     * @var array $dates
70
     */
71
    protected $dates =
72
      [
73
        'created_at',
74
        'updated_at',
75
        'deleted_at'
76
      ];
77
78
    protected $appends =
79
      [
80
        'is_active'
81
      ];
82
83
    /**
84
     * Returns the full name of user.
85
     *
86
     * @return string
87
     */
88
    public function getFullNameAttribute($value)
89
    {
90
        return ucfirst($this->first_name).' '.ucfirst($this->last_name);
91
    }
92
93
    /**
94
     * Get user avatar or set default.png as default.
95
     *
96
     * @return string
97
     */
98
    public function getAvatarAttribute($avatar)
99
    {
100
        return asset($avatar ?: 'images/avatars/default.png');
101
    }
102
103
    /**
104
     * Returns the campaigns created by the user.
105
     *
106
     * @return \Illuminate\Database\Eloquent\Relations\HasMany relationship
107
     * @var    array
108
     */
109
    public function campaigns()
110
    {
111
        return $this->hasMany(Campaign::class);
112
    }
113
114
    /**
115
     * Related.
116
     *
117
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
118
     */
119
    public function bloodType()
120
    {
121
        return $this->belongsTo(BloodType::class, 'blood_type_id');
122
    }
123
124
    /**
125
     * Return as Many invites created by user.
126
     */
127
    public function invites()
128
    {
129
        return $this->hasMany(Invite::class);
130
    }
131
132
    /**
133
     * Returns the comments created by the user.
134
     *
135
     * @return \Illuminate\Database\Eloquent\Relations\HasMany relationship
136
     * @var    array
137
     */
138
    public function comments()
139
    {
140
        return $this->hasMany(Comment::class);
141
    }
142
143
    public function getIsActiveAttribute()
144
    {
145
        return $this->attributes[ 'status' ] == "active";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal active does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
146
    }
147
148
    /**
149
     * Get the route key for the model.
150
     *
151
     * @return string
152
     */
153
    public function getRouteKeyName()
154
    {
155
        return 'username';
156
    }
157
158
    /**
159
     * Get the user phone number
160
     *
161
     * @return string
162
     */
163
    public function getPhoneNumberAttribute()
164
    {
165
        return $this->attributes[ 'country_code' ].$this->attributes[ 'phone' ];
166
    }
167
168
    /**
169
     * Generate automaticaly the User uuid.
170
     *
171
     * @return void
172
     */
173 3
    public static function boot()
174
    {
175 3
        parent::boot();
176 3
        self::creating(
177 3
            function($model) {
178
                // Generate a version 4 Uuid.
179 3
                $model->id = (string) Uuid::generate(4)->string;
180 3
            }
181
        );
182
    }
183
184
}
185