Completed
Push — master ( c7d5ad...0208a8 )
by Sherif
02:59
created

InitializeLogging::up()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 77
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 77
rs 8.9342
cc 2
eloc 39
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 InitializeLogging 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
         * Delete previous permissions.
17
         */
18
		DB::table('permissions')->whereIn('model', ['logs'])->delete();
19
20
		 /**
21
         * Insert the permissions related to this module.
22
         */
23
        DB::table('permissions')->insert(
24
        	[
25
        		/**
26
        		 * Logs model permissions.
27
        		 */
28
	        	[
29
	        	'name'       => 'find',
30
	        	'model'      => 'logs',
31
	        	'created_at' => \DB::raw('NOW()'),
32
	        	'updated_at' => \DB::raw('NOW()')
33
	        	],
34
	        	[
35
	        	'name'       => 'search',
36
	        	'model'      => 'logs',
37
	        	'created_at' => \DB::raw('NOW()'),
38
	        	'updated_at' => \DB::raw('NOW()')
39
	        	],
40
	        	[
41
	        	'name'       => 'list',
42
	        	'model'      => 'logs',
43
	        	'created_at' => \DB::raw('NOW()'),
44
	        	'updated_at' => \DB::raw('NOW()')
45
	        	],
46
	        	[
47
	        	'name'       => 'findby',
48
	        	'model'      => 'logs',
49
	        	'created_at' => \DB::raw('NOW()'),
50
	        	'updated_at' => \DB::raw('NOW()')
51
	        	],
52
	        	[
53
	        	'name'       => 'first',
54
	        	'model'      => 'logs',
55
	        	'created_at' => \DB::raw('NOW()'),
56
	        	'updated_at' => \DB::raw('NOW()')
57
	        	],
58
	        	[
59
	        	'name'       => 'paginate',
60
	        	'model'      => 'logs',
61
	        	'created_at' => \DB::raw('NOW()'),
62
	        	'updated_at' => \DB::raw('NOW()')
63
	        	],
64
	        	[
65
	        	'name'       => 'paginateby',
66
	        	'model'      => 'logs',
67
	        	'created_at' => \DB::raw('NOW()'),
68
	        	'updated_at' => \DB::raw('NOW()')
69
	        	],
70
        	]
71
        );
72
73
        /**
74
		 * Assign the permissions to the admin group.
75
		 */
76
		$permissionIds = DB::table('permissions')->whereIn('model', ['logs'])->select('id')->lists('id');
77
		$adminGroupId  = DB::table('groups')->where('name', 'Admin')->first()->id;
78
		foreach ($permissionIds as $permissionId) 
79
		{
80
			DB::table('groups_permissions')->insert(
81
				[
82
				'permission_id' => $permissionId,
83
				'group_id'      => $adminGroupId,
84
				'created_at'    => \DB::raw('NOW()'),
85
				'updated_at'    => \DB::raw('NOW()')
86
				]
87
			);
88
		}
89
	}
90
91
	/**
92
	 * Reverse the migrations.
93
	 *
94
	 * @return void
95
	 */
96
	public function down()
97
	{
98
		$adminGroupId = DB::table('groups')->where('name', 'Admin')->first()->id;
99
		$adminUserId  = DB::table('users')->where('email', '[email protected]')->first()->id;
100
101
		DB::table('permissions')->whereIn('model', ['logs'])->delete();
102
		DB::table('users_groups')->where('user_id', $adminUserId)->where('group_id', $adminGroupId)->delete();
103
	}
104
}