Completed
Push — master ( fb73c0...e952da )
by Sherif
07:01
created

InitializeReports::up()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 78
Code Lines 42

Duplication

Lines 11
Ratio 14.1 %

Importance

Changes 0
Metric Value
dl 11
loc 78
rs 8.9019
c 0
b 0
f 0
cc 2
eloc 42
nc 2
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
use Illuminate\Database\Schema\Blueprint;
4
use Illuminate\Database\Migrations\Migration;
5
6
class InitializeReports extends Migration
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
{
8
	/**
9
	 * Run the migrations.
10
	 *
11
	 * @return void
12
	 */
13
	public function up()
14
	{
15
		/**
16
         * Insert the permissions related to this module.
17
         */
18
        DB::table('permissions')->insert(
19
        	[
20
        		/**
21
        		 * Reporting model permissions.
22
        		 */
23
	        	[
24
	        	'name'       => 'find',
25
	        	'model'      => 'reports',
26
	        	'created_at' => \DB::raw('NOW()'),
27
	        	'updated_at' => \DB::raw('NOW()')
28
	        	],
29
	        	[
30
	        	'name'       => 'search',
31
	        	'model'      => 'reports',
32
	        	'created_at' => \DB::raw('NOW()'),
33
	        	'updated_at' => \DB::raw('NOW()')
34
	        	],
35
	        	[
36
	        	'name'       => 'list',
37
	        	'model'      => 'reports',
38
	        	'created_at' => \DB::raw('NOW()'),
39
	        	'updated_at' => \DB::raw('NOW()')
40
	        	],
41
	        	[
42
	        	'name'       => 'findby',
43
	        	'model'      => 'reports',
44
	        	'created_at' => \DB::raw('NOW()'),
45
	        	'updated_at' => \DB::raw('NOW()')
46
	        	],
47
	        	[
48
	        	'name'       => 'first',
49
	        	'model'      => 'reports',
50
	        	'created_at' => \DB::raw('NOW()'),
51
	        	'updated_at' => \DB::raw('NOW()')
52
	        	],
53
	        	[
54
	        	'name'       => 'paginate',
55
	        	'model'      => 'reports',
56
	        	'created_at' => \DB::raw('NOW()'),
57
	        	'updated_at' => \DB::raw('NOW()')
58
	        	],
59
	        	[
60
	        	'name'       => 'paginateby',
61
	        	'model'      => 'reports',
62
	        	'created_at' => \DB::raw('NOW()'),
63
	        	'updated_at' => \DB::raw('NOW()')
64
	        	],
65
	        	[
66
	        	'name'       => 'admin_count',
67
	        	'model'      => 'reports',
68
	        	'created_at' => \DB::raw('NOW()'),
69
	        	'updated_at' => \DB::raw('NOW()')
70
	        	]
71
        	]
72
        );
73
74
        /**
75
		 * Assign the permissions to the admin group.
76
		 */
77
		$permissionIds = DB::table('permissions')->whereIn('model', ['reports'])->select('id')->pluck('id');
78
		$adminGroupId  = DB::table('groups')->where('name', 'Admin')->first()->id;
79 View Code Duplication
		foreach ($permissionIds as $permissionId) 
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
		{
81
			DB::table('groups_permissions')->insert(
82
				[
83
				'permission_id' => $permissionId,
84
				'group_id'      => $adminGroupId,
85
				'created_at'    => \DB::raw('NOW()'),
86
				'updated_at'    => \DB::raw('NOW()')
87
				]
88
			);
89
		}
90
	}
91
92
	/**
93
	 * Reverse the migrations.
94
	 *
95
	 * @return void
96
	 */
97
	public function down()
98
	{
99
		$permissions  = DB::table('permissions')->whereIn('model', ['reports']);
100
		DB::table('groups_permissions')->whereIn('permission_id', $permissions->pluck('id'))->delete();
101
		$permissions->delete();
102
	}
103
}