BaseMigration   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 53
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A table() 0 3 1
A rename() 0 3 1
A drop() 0 3 1
A create() 0 3 1
A schema() 0 4 1
A dropTables() 0 4 2
1
<?php
2
3
namespace Helldar\Roles\Support\Database;
4
5
use Closure;
6
use Helldar\Roles\Constants\Tables;
7
use Helldar\Roles\Facades\Config;
8
use Illuminate\Database\Migrations\Migration;
9
use Illuminate\Database\Schema\Builder;
10
use Illuminate\Support\Facades\Schema;
11
12
abstract class BaseMigration extends Migration
13
{
14
    protected $permissions = Tables::PERMISSIONS;
15
16
    protected $role_permission = Tables::ROLE_PERMISSION;
17
18
    protected $role_permissions = 'role_permissions';
19
20
    protected $roles = Tables::ROLES;
21
22
    protected $user_permission = Tables::USER_PERMISSION;
23
24
    protected $user_role = Tables::USER_ROLE;
25
26
    protected $user_roles = 'user_roles';
27
28
    protected $users = 'users';
29
30
    abstract public function up();
31
32
    abstract public function down();
33
34 138
    protected function schema(): Builder
35
    {
36 138
        return Schema::connection(
37 138
            Config::connection()
38
        );
39
    }
40
41 138
    protected function create(string $table, Closure $callback)
42
    {
43 138
        $this->schema()->create($table, $callback);
44 138
    }
45
46 138
    protected function drop(string $table)
47
    {
48 138
        $this->schema()->dropIfExists($table);
49 138
    }
50
51 138
    protected function table(string $table, Closure $callback)
52
    {
53 138
        $this->schema()->table($table, $callback);
54 138
    }
55
56 138
    protected function rename(string $from, string $to)
57
    {
58 138
        $this->schema()->rename($from, $to);
59 138
    }
60
61 138
    protected function dropTables(...$tables)
62
    {
63 138
        foreach ($tables as $table) {
64 138
            $this->drop($table);
65
        }
66 138
    }
67
}
68