Passed
Push — main ( 131f20...c1d479 )
by Rafael
51:37
created

User::getToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Alxarafe\Model;
4
5
use Alxarafe\Base\Model\Model;
6
use Illuminate\Database\Capsule\Manager as DB;
7
use Illuminate\Database\Schema\Blueprint;
8
9
class User extends Model
10
{
11
    protected $table = 'users';
12
    protected $fillable = ['name', 'email', 'password', 'token', 'is_admin'];
13
14
    public static function createTable()
15
    {
16
        DB::schema()->create((new static())->table, function (Blueprint $table) {
17
            $table->increments('id');
18
            $table->string('name');
19
            $table->string('email')->unique();
20
            $table->string('password');
21
            $table->string('token')->nullable();
22
            $table->boolean('is_admin')->default(false);
23
            $table->timestamps();
24
        });
25
    }
26
27
    public static function createAdmin(): bool
28
    {
29
        return (null !== User::create([
30
                'name' => 'admin',
31
                'email' => '[email protected]',
32
                'password' => password_hash('password', PASSWORD_ARGON2ID),
33
                'token' => null,
34
                'is_admin' => true,
35
            ])
36
        );
37
    }
38
39
    public function saveToken($token)
40
    {
41
        $this->token = $token;
0 ignored issues
show
Bug introduced by
The property token does not seem to exist on Alxarafe\Model\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...
42
        return $this->save();
43
    }
44
45
    public function getToken()
46
    {
47
        return $this->token;
48
    }
49
}
50