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

BaseMigration::rename()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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