Passed
Push — master ( 6da38c...408d25 )
by Andrey
17:24 queued 14:36
created

BaseMigration   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

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

6 Methods

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