CheckQueryIsAuthorized::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace EloquentJs\Query\Listeners;
4
5
use EloquentJs\Query\Events\EloquentJsWasCalled;
6
use EloquentJs\Query\Guard\Guard;
7
use EloquentJs\Query\Guard\NotPermittedException;
8
use EloquentJs\Query\Guard\Policy\Factory;
9
use EloquentJs\Query\Query;
10
11
class CheckQueryIsAuthorized
12
{
13
    /**
14
     * @var Guard
15
     */
16
    protected $guard;
17
18
    /**
19
     * @var Query
20
     */
21
    protected $query;
22
23
    /**
24
     * @var Factory
25
     */
26
    protected $policy;
27
28
    /**
29
     * Create the event listener.
30
     *
31
     * @param Guard $guard
32
     * @param Query $query
33
     * @param Factory $policy
34
     */
35
    public function __construct(Guard $guard, Query $query, Factory $policy)
36
    {
37
        $this->guard = $guard;
38
        $this->query = $query;
39
        $this->policy = $policy;
40
    }
41
42
    /**
43
     * Handle the event.
44
     *
45
     * @param EloquentJsWasCalled $event
46
     * @throws NotPermittedException
47
     */
48
    public function handle(EloquentJsWasCalled $event)
49
    {
50
        $this->guard->authorize($this->query, $this->policy->make($event->rules));
51
    }
52
}