AccessCore   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
dl 0
loc 46
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A uninstall() 0 6 1
A install() 0 11 2
A boot() 0 5 1
A defaultRoles() 0 7 1
1
<?php
2
3
namespace Epesi\Core\System\User\Access;
4
5
use Spatie\Permission\Models\Permission;
6
use Spatie\Permission\Models\Role;
7
use Epesi\Core\System\Modules\ModuleCore;
8
use Epesi\Core\System\User\Access\Integration\UserAccessSystemSettings;
9
use Illuminate\Support\Facades\Gate;
10
11
class AccessCore extends ModuleCore
12
{
13
	protected static $alias = 'user.access';
14
	
15
	protected static $view = AccessSettings::class;
16
	
17
	protected static $joints = [
18
			UserAccessSystemSettings::class
19
	];
20
	
21
	public function defaultRoles()
22
	{
23
		return [
24
				'Super Admin',
25
				'Admin',
26
				'Employee',
27
				'Guest'
28
		];
29
	}
30
	
31
	public function install()
32
	{
33
		foreach ($this->defaultRoles() as $roleName) {
34
			Role::create(['name' => $roleName]);
35
		}
36
		
37
		Permission::create(['name' => 'modify system']);
38
		
39
		$modifySystemSettings = Permission::create(['name' => 'modify system settings']);
40
		
41
		Role::findByName('Admin')->givePermissionTo($modifySystemSettings);
42
	}
43
44
	public function uninstall()
45
	{
46
		Role::whereIn('name', $this->defaultRoles())->delete();
47
		
48
		Permission::findByName('modify system')->delete();
49
		Permission::findByName('modify system settings')->delete();
50
	}
51
	
52
	public static function boot()
53
	{
54
		// allow Super Admin full access
55
		Gate::after(function ($user, $ability) {
0 ignored issues
show
Unused Code introduced by
The parameter $ability is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

55
		Gate::after(function ($user, /** @scrutinizer ignore-unused */ $ability) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
			return $user->hasRole('Super Admin');
57
		});
58
	}
59
}
60