AclSeeder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 79.17 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 38
loc 48
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 6 1
A insertPermissions() 12 12 1
A insertRoles() 12 12 1
A linkRolesAndPermissions() 13 12 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 Illuminate\Database\Seeder;
4
5
class AclSeeder extends Seeder {
6
7
    public function run()
8
    {
9
        $this->insertPermissions();
10
        $this->insertRoles();
11
        $this->linkRolesAndPermissions();
12
    }
13
14 View Code Duplication
    private function insertPermissions()
15
    {
16
        // Truncate the table each time.
17
        DB::statement('SET FOREIGN_KEY_CHECKS=0;');
18
        DB::table('acl_permissions')->truncate();
19
        DB::statement('SET FOREIGN_KEY_CHECKS=1;');
20
21
        $permissions = config('users.permissions');
22
23
        // Add any data to the table.
24
        DB::table('acl_permissions')->insert($permissions);
25
    }
26
27 View Code Duplication
    private function insertRoles()
28
    {
29
        // Truncate the table each time.
30
        DB::statement('SET FOREIGN_KEY_CHECKS=0;');
31
        DB::table('acl_roles')->truncate();
32
        DB::statement('SET FOREIGN_KEY_CHECKS=1;');
33
34
        $roles = config('users.roles');
35
36
        // Add any data to the table.
37
        DB::table('acl_roles')->insert($roles);
38
    }
39
40 View Code Duplication
    private function linkRolesAndPermissions()
41
    {
42
        // Truncate the table each time.
43
        DB::statement('SET FOREIGN_KEY_CHECKS=0;');
44
        DB::table('acl_permission_role')->truncate();
45
        DB::statement('SET FOREIGN_KEY_CHECKS=1;');
46
47
        $permissions = config('users.permission_role');
48
49
        // Add any data to the table.
50
        DB::table('acl_permission_role')->insert($permissions);
51
    }
52
}
53