Passed
Push — master ( feb473...abec42 )
by Georgi
02:54
created

AccessCore   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A install() 0 11 2
A uninstall() 0 6 1
A defaultRoles() 0 7 1
1
<?php
2
3
namespace Epesi\Base\User\Access;
4
5
use Spatie\Permission\Models\Permission;
6
use Spatie\Permission\Models\Role;
7
use Epesi\Core\System\Integration\Modules\ModuleCore;
0 ignored issues
show
Bug introduced by
The type Epesi\Core\System\Integration\Modules\ModuleCore was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Epesi\Base\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 $joints = [
16
			UserAccessSystemSettings::class
17
	];
18
	
19
	public function defaultRoles()
20
	{
21
		return [
22
				'Super Admin',
23
				'Admin',
24
				'Employee',
25
				'Guest'
26
		];
27
	}
28
	
29
	public function install()
30
	{
31
		foreach ($this->defaultRoles() as $roleName) {
32
			Role::create(['name' => $roleName]);
33
		}
34
		
35
		Permission::create(['name' => 'modify system']);
36
		
37
		$modifySystemSettings = Permission::create(['name' => 'modify system settings']);
38
		
39
		Role::findByName('Admin')->givePermissionTo($modifySystemSettings);
40
	}
41
42
	public function uninstall()
43
	{
44
		Role::whereIn('name', $this->defaultRoles())->delete();
45
		
46
		Permission::findByName('modify system')->delete();
47
		Permission::findByName('modify system settings')->delete();
48
	}
49
	
50
	public static function boot()
51
	{
52
		// allow Super Admin full access
53
		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

53
		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...
54
			return $user->hasRole('Super Admin');
55
		});
56
	}
57
}
58