Passed
Branch master (c62005)
by ABDULMALIK
02:15
created

CreateRolePermission   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 19
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 2
dl 19
loc 19
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A change() 0 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
5
/**
6
 * Class CreateRolePermission
7
 */
8
class CreateRolePermission extends AbstractMigration
9
{
10
    /**
11
     * Create 'role_permission' table in database.
12
     * 'role_id' with 'permission_id' creates unique index.
13
     */
14
    public function change()
15
    {
16
        $rolePermissionTable = $this->table('role_permission', ['signed' => false]);
17
18
        $rolePermissionTable->addColumn('role_id', 'integer', ['signed' => false])
19
            ->addColumn('permission_id', 'integer', ['signed' => false])
20
            ->addColumn('created_at', 'datetime')
21
            ->addIndex(['role_id', 'permission_id'], ['name' => 'idx_role_permission_unique', 'unique' => true])
22
            ->addForeignKey('role_id', 'role', 'id', ['delete' => 'RESTRICT', 'constraint' => 'fk_role_permission_role'])
23
            ->addForeignKey('permission_id', 'permission', 'id', ['delete' => 'RESTRICT', 'constraint' => 'fk_role_permission_permission'])
24
            ->create();
25
    }
26
}
27