Test Failed
Push — master ( 3e81ac...787e81 )
by Iman
02:36
created

HeyManServiceProvider::defineGates()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan;
4
5
use Illuminate\Support\Facades\Gate;
6
use Illuminate\Support\ServiceProvider;
7
8
class HeyManServiceProvider extends ServiceProvider
9
{
10
    public function boot()
11
    {
12
        $this->defineGates();
13
14
        $this->loadMigrationsFrom(__DIR__.'/migrations');
15
        (new RouteAuthorizer())->authorizeMatchedRoutes($this->app);
16
    }
17
18
    public function register()
19
    {
20
        $this->app->singleton(HeyMan::class, HeyMan::class);
21
        $this->app->singleton('hey_man_authorizer', ConditionApplier::class);
22
        $this->app->singleton('hey_man_route_authorizer', RouteConditionApplier::class);
23
        $this->app->singleton(YouShouldHave::class, YouShouldHave::class);
24
        $this->app->singleton('hey_man_responder', Responder::class);
25
26
        $this->mergeConfigFrom(
27
            __DIR__.'/../config/heyMan.php',
28
            'heyMan'
29
        );
30
    }
31
32
    private function defineGates(): void
33
    {
34
        Gate::define('heyman.youShouldHaveRole', function ($user, $role) {
35
            return $user->role == $role;
36
        });
37
    }
38
}