Test Failed
Push — main ( 82933d...ebe982 )
by Rafael
02:28
created

User   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A saveToken() 0 4 1
A getToken() 0 3 1
A createAdmin() 0 8 1
A createTable() 0 10 1
1
<?php
2
3
namespace Alxarafe\Model;
4
5
use Alxarafe\Base\Model\Model;
6
use Illuminate\Database\Capsule\Manager as DB;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Capsule\Manager was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Illuminate\Database\Schema\Blueprint;
0 ignored issues
show
Bug introduced by
The type Illuminate\Database\Schema\Blueprint was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class User extends Model
10
{
11
    protected $table = 'users';
12
    protected $fillable = ['name', 'email', 'password', 'token', 'is_admin'];
13
    protected $hidden = ['password', 'token'];
14
15
    public static function createTable()
16
    {
17
        DB::schema()->create((new static())->table, function (Blueprint $table) {
18
            $table->increments('id');
19
            $table->string('name');
20
            $table->string('email')->unique();
21
            $table->string('password');
22
            $table->string('token')->nullable();
23
            $table->boolean('is_admin')->default(false);
24
            $table->timestamps();
25
        });
26
    }
27
28
    public static function createAdmin(): bool
29
    {
30
        return (null !== User::create([
31
                'name' => 'admin',
32
                'email' => '[email protected]',
33
                'password' => password_hash('password', PASSWORD_ARGON2ID),
34
                'token' => null,
35
                'is_admin' => true,
36
            ])
37
        );
38
    }
39
40
    public function saveToken($token)
41
    {
42
        $this->attributes['token'] = $token;
0 ignored issues
show
Bug Best Practice introduced by
The property attributes does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
43
        return $this->save();
44
    }
45
46
    public function getToken()
47
    {
48
        return $this->attributes['token'];
49
    }
50
}
51