UserStampsMacro   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Importance

Changes 6
Bugs 2 Features 2
Metric Value
eloc 56
c 6
b 2
f 2
dl 0
loc 100
rs 10
wmc 14

5 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 6 1
A registerDropUserstamps() 0 18 3
A registerUserstamps() 0 28 4
A registerSoftUserstamps() 0 19 4
A registerDropSoftUserstamps() 0 10 2
1
<?php
2
3
namespace Sqits\UserStamps\Database\Schema\Macros;
4
5
use Illuminate\Database\Schema\Blueprint;
6
use Illuminate\Database\SQLiteConnection;
7
use Illuminate\Support\Facades\DB;
8
9
class UserStampsMacro implements MacroInterface
10
{
11
    /**
12
     * Bootstrap the schema macro.
13
     *
14
     * @return void
15
     */
16
    public function register()
17
    {
18
        $this->registerUserstamps();
19
        $this->registerSoftUserstamps();
20
        $this->registerDropUserstamps();
21
        $this->registerDropSoftUserstamps();
22
    }
23
24
    private function registerUserstamps()
25
    {
26
        Blueprint::macro('userstamps', function () {
27
            if (config('userstamps.users_table_column_type') === 'bigIncrements') {
28
                $this->unsignedBigInteger(config('userstamps.created_by_column'))->nullable();
0 ignored issues
show
Bug introduced by
The method unsignedBigInteger() does not exist on Sqits\UserStamps\Databas...\Macros\UserStampsMacro. ( Ignorable by Annotation )

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

28
                $this->/** @scrutinizer ignore-call */ 
29
                       unsignedBigInteger(config('userstamps.created_by_column'))->nullable();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
                $this->unsignedBigInteger(config('userstamps.updated_by_column'))->nullable();
30
            } elseif (config('userstamps.users_table_column_type') === 'uuid') {
31
                $this->uuid(config('userstamps.created_by_column'))->nullable();
0 ignored issues
show
Bug introduced by
The method uuid() does not exist on Sqits\UserStamps\Databas...\Macros\UserStampsMacro. ( Ignorable by Annotation )

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

31
                $this->/** @scrutinizer ignore-call */ 
32
                       uuid(config('userstamps.created_by_column'))->nullable();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
                $this->uuid(config('userstamps.updated_by_column'))->nullable();
33
            } elseif (config('userstamps.users_table_column_type') === 'ulid') {
34
                $this->ulid(config('userstamps.created_by_column'))->nullable();
0 ignored issues
show
Bug introduced by
The method ulid() does not exist on Sqits\UserStamps\Databas...\Macros\UserStampsMacro. ( Ignorable by Annotation )

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

34
                $this->/** @scrutinizer ignore-call */ 
35
                       ulid(config('userstamps.created_by_column'))->nullable();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
35
                $this->ulid(config('userstamps.updated_by_column'))->nullable();
36
            } else {
37
                $this->unsignedInteger(config('userstamps.created_by_column'))->nullable();
0 ignored issues
show
Bug introduced by
The method unsignedInteger() does not exist on Sqits\UserStamps\Databas...\Macros\UserStampsMacro. ( Ignorable by Annotation )

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

37
                $this->/** @scrutinizer ignore-call */ 
38
                       unsignedInteger(config('userstamps.created_by_column'))->nullable();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
                $this->unsignedInteger(config('userstamps.updated_by_column'))->nullable();
39
            }
40
41
            $this->foreign(config('userstamps.created_by_column'))
0 ignored issues
show
Bug introduced by
The method foreign() does not exist on Sqits\UserStamps\Databas...\Macros\UserStampsMacro. ( Ignorable by Annotation )

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

41
            $this->/** @scrutinizer ignore-call */ 
42
                   foreign(config('userstamps.created_by_column'))

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
                ->references(config('userstamps.users_table_column_id_name'))
43
                ->on(config('userstamps.users_table'))
44
                ->onDelete('set null');
45
46
            $this->foreign(config('userstamps.updated_by_column'))
47
                ->references(config('userstamps.users_table_column_id_name'))
48
                ->on(config('userstamps.users_table'))
49
                ->onDelete('set null');
50
51
            return $this;
52
        });
53
    }
54
55
    private function registerSoftUserstamps()
56
    {
57
        Blueprint::macro('softUserstamps', function () {
58
            if (config('userstamps.users_table_column_type') === 'bigIncrements') {
59
                $this->unsignedBigInteger(config('userstamps.deleted_by_column'))->nullable();
60
            } elseif (config('userstamps.users_table_column_type') === 'uuid') {
61
                $this->uuid(config('userstamps.deleted_by_column'))->nullable();
62
            } elseif (config('userstamps.users_table_column_type') === 'ulid') {
63
                $this->ulid(config('userstamps.deleted_by_column'))->nullable();
64
            } else {
65
                $this->unsignedInteger(config('userstamps.deleted_by_column'))->nullable();
66
            }
67
68
            $this->foreign(config('userstamps.deleted_by_column'))
69
                ->references(config('userstamps.users_table_column_id_name'))
70
                ->on(config('userstamps.users_table'))
71
                ->onDelete('set null');
72
73
            return $this;
74
        });
75
    }
76
77
    private function registerDropUserstamps()
78
    {
79
        Blueprint::macro('dropUserstamps', function () {
80
            if (! DB::connection() instanceof SQLiteConnection) {
81
                $this->dropForeign([
0 ignored issues
show
Bug introduced by
The method dropForeign() does not exist on Sqits\UserStamps\Databas...\Macros\UserStampsMacro. ( Ignorable by Annotation )

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

81
                $this->/** @scrutinizer ignore-call */ 
82
                       dropForeign([

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
82
                    config('userstamps.created_by_column'),
83
                ]);
84
            }
85
86
            if (! DB::connection() instanceof SQLiteConnection) {
87
                $this->dropForeign([
88
                    config('userstamps.updated_by_column'),
89
                ]);
90
            }
91
92
            $this->dropColumn([
0 ignored issues
show
Bug introduced by
The method dropColumn() does not exist on Sqits\UserStamps\Databas...\Macros\UserStampsMacro. ( Ignorable by Annotation )

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

92
            $this->/** @scrutinizer ignore-call */ 
93
                   dropColumn([

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
93
                config('userstamps.created_by_column'),
94
                config('userstamps.updated_by_column'),
95
            ]);
96
        });
97
    }
98
99
    private function registerDropSoftUserstamps()
100
    {
101
        Blueprint::macro('dropSoftUserstamps', function () {
102
            if (! DB::connection() instanceof SQLiteConnection) {
103
                $this->dropForeign([
104
                    config('userstamps.deleted_by_column'),
105
                ]);
106
            }
107
108
            $this->dropColumn(config('userstamps.deleted_by_column'));
109
        });
110
    }
111
}
112