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

CreateRoleHierarchy   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
4
use Phinx\Migration\AbstractMigration;
5
6
class CreateRoleHierarchy extends AbstractMigration
7
{
8
    /**
9
     * Create 'role_hierarchy' table
10
     * 'parent_role_id' with 'child_role_id' creates unique index.
11
     */
12
    public function change()
13
    {
14
        $userRoleTable = $this->table('role_hierarchy', ['signed' => false]);
15
16
        $userRoleTable->addColumn('parent_role_id', 'integer', ['signed' => false])
17
            ->addColumn('child_role_id', 'integer', ['signed' => false])
18
            ->addColumn('created_at', 'datetime')
19
            ->addIndex(['parent_role_id', 'child_role_id'], ['name' => 'idx_role_hierarchy_unique', 'unique' => true])
20
            ->addForeignKey('parent_role_id', 'role', 'id', ['delete' => 'RESTRICT', 'constraint' => 'fk_role_hierarchy_parent'])
21
            ->addForeignKey('child_role_id', 'role', 'id', ['delete' => 'RESTRICT', 'constraint' => 'fk_role_hierarchy_child'])
22
            ->create();
23
    }
24
}
25