Passed
Branch master (d88b3b)
by Prateek
03:56
created

User::generateToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace App;
4
5
use Illuminate\Notifications\Notifiable;
6
use Illuminate\Foundation\Auth\User as Authenticatable;
7
use Spatie\Permission\Traits\HasRoles;
8
9
class User extends Authenticatable
10
{
11
	use HasRoles;
0 ignored issues
show
introduced by
The trait Spatie\Permission\Traits\HasRoles requires some properties which are not provided by App\User: $name, $map, $permissions, $roles, $guard_name
Loading history...
12
    use Notifiable;
0 ignored issues
show
introduced by
The trait Illuminate\Notifications\Notifiable requires some properties which are not provided by App\User: $email, $phone_number
Loading history...
13
14
    /**
15
     * The attributes that are mass assignable.
16
     *
17
     * @var array
18
     */
19
    protected $fillable = [
20
        'name', 'email', 'password',
21
    ];
22
23
    /**
24
     * The attributes that should be hidden for arrays.
25
     *
26
     * @var array
27
     */
28
    protected $hidden = [
29
        'password', 'remember_token',
30
    ];
31
32
    /**
33
     * The attributes that should be cast to native types.
34
     *
35
     * @var array
36
     */
37
    protected $casts = [
38
        'email_verified_at' => 'datetime',
39
    ];
40
41
    public function generateToken()
42
    {
43
        $this->api_token = str_random(60);
0 ignored issues
show
Deprecated Code introduced by
The function str_random() has been deprecated: Str::random() should be used directly instead. Will be removed in Laravel 5.9. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

43
        $this->api_token = /** @scrutinizer ignore-deprecated */ str_random(60);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Bug introduced by
The property api_token does not seem to exist on App\User. 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...
44
        $this->save();
45
46
        return $this->api_token;
47
    }
48
}
49