CreateMobileVerificationTokensTable::down()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
use Illuminate\Config\Repository;
4
use Illuminate\Database\Migrations\Migration;
5
use Illuminate\Database\Schema\Blueprint;
6
use Illuminate\Support\Facades\Schema;
7
8
class CreateMobileVerificationTokensTable extends Migration
9
{
10
    /**
11
     * @var Repository
12
     */
13
    private $userTable;
14
15
    /**
16
     * @var Repository
17
     */
18
    private $tokenTable;
19
20
    /**
21
     * @var Repository
22
     */
23
    private $mobileColumn;
24
25
    /**
26
     * CreateMobileVerificationTokensTable constructor.
27
     */
28
    public function __construct()
29
    {
30
        $this->userTable = config('mobile_verifier.user_table', 'users');
31
        $this->mobileColumn = config('mobile_verifier.mobile_column', 'mobile');
32
        $this->tokenTable = config('mobile_verifier.token_table', 'mobile_verification_tokens');
33
    }
34
35
    /**
36
     * Run the migrations.
37
     *
38
     * @return void
39
     */
40
    public function up(): void
41
    {
42
        Schema::create($this->tokenTable, static function (Blueprint $table) {
0 ignored issues
show
Bug introduced by
$this->tokenTable of type Illuminate\Config\Repository is incompatible with the type string expected by parameter $table of Illuminate\Support\Facades\Schema::create(). ( Ignorable by Annotation )

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

42
        Schema::create(/** @scrutinizer ignore-type */ $this->tokenTable, static function (Blueprint $table) {
Loading history...
43
            $table->increments('id');
44
            $table->string('mobile')->index();
45
            $table->string('token', 10)->index();
46
            $table->timestamp('expires_at')->nullable();
47
48
            $table->index(['mobile', 'token']);
49
        });
50
51
        if (!Schema::hasColumn($this->userTable, $this->mobileColumn)) {
0 ignored issues
show
Bug introduced by
$this->mobileColumn of type Illuminate\Config\Repository is incompatible with the type string expected by parameter $column of Illuminate\Support\Facades\Schema::hasColumn(). ( Ignorable by Annotation )

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

51
        if (!Schema::hasColumn($this->userTable, /** @scrutinizer ignore-type */ $this->mobileColumn)) {
Loading history...
Bug introduced by
$this->userTable of type Illuminate\Config\Repository is incompatible with the type string expected by parameter $table of Illuminate\Support\Facades\Schema::hasColumn(). ( Ignorable by Annotation )

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

51
        if (!Schema::hasColumn(/** @scrutinizer ignore-type */ $this->userTable, $this->mobileColumn)) {
Loading history...
52
            Schema::table($this->userTable, function (Blueprint $table) {
0 ignored issues
show
Bug introduced by
$this->userTable of type Illuminate\Config\Repository is incompatible with the type string expected by parameter $table of Illuminate\Support\Facades\Schema::table(). ( Ignorable by Annotation )

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

52
            Schema::table(/** @scrutinizer ignore-type */ $this->userTable, function (Blueprint $table) {
Loading history...
53
                $table->string($this->mobileColumn);
0 ignored issues
show
Bug introduced by
$this->mobileColumn of type Illuminate\Config\Repository is incompatible with the type string expected by parameter $column of Illuminate\Database\Schema\Blueprint::string(). ( Ignorable by Annotation )

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

53
                $table->string(/** @scrutinizer ignore-type */ $this->mobileColumn);
Loading history...
54
            });
55
        }
56
57
        if (!Schema::hasColumn($this->userTable, 'mobile_verified_at')) {
58
            Schema::table($this->userTable, function (Blueprint $table) {
59
                $table->timestamp('mobile_verified_at')->nullable()->after($this->mobileColumn);
0 ignored issues
show
Bug introduced by
$this->mobileColumn of type Illuminate\Config\Repository is incompatible with the type string expected by parameter $column of Illuminate\Database\Sche...lumnDefinition::after(). ( Ignorable by Annotation )

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

59
                $table->timestamp('mobile_verified_at')->nullable()->after(/** @scrutinizer ignore-type */ $this->mobileColumn);
Loading history...
60
            });
61
        }
62
    }
63
64
    /**
65
     * Reverse the migrations.
66
     *
67
     * @return void
68
     */
69
    public function down(): void
70
    {
71
        Schema::drop($this->tokenTable);
0 ignored issues
show
Bug introduced by
$this->tokenTable of type Illuminate\Config\Repository is incompatible with the type string expected by parameter $table of Illuminate\Support\Facades\Schema::drop(). ( Ignorable by Annotation )

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

71
        Schema::drop(/** @scrutinizer ignore-type */ $this->tokenTable);
Loading history...
72
73
        Schema::table($this->userTable, static function (Blueprint $table) {
0 ignored issues
show
Bug introduced by
$this->userTable of type Illuminate\Config\Repository is incompatible with the type string expected by parameter $table of Illuminate\Support\Facades\Schema::table(). ( Ignorable by Annotation )

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

73
        Schema::table(/** @scrutinizer ignore-type */ $this->userTable, static function (Blueprint $table) {
Loading history...
74
            $table->dropColumn('mobile_verified_at');
75
        });
76
    }
77
}
78