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

InitializeCore::up()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 83
Code Lines 43

Duplication

Lines 83
Ratio 100 %

Importance

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