GetRequest::authorize()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
namespace FaithGen\Sermons\Http\Requests;
4
5
use FaithGen\SDK\Models\Ministry;
6
use FaithGen\Sermons\SermonService;
7
use Illuminate\Auth\Access\AuthorizationException;
8
use Illuminate\Foundation\Http\FormRequest;
9
10
class GetRequest extends FormRequest
11
{
12
    /**
13
     * Determine if the user is authorized to make this request.
14
     *
15
     * @param \FaithGen\Sermons\SermonService $sermonService
16
     *
17
     * @return bool
18
     */
19
    public function authorize(SermonService $sermonService)
20
    {
21
        if (auth()->user() instanceof Ministry) {
22
            return $this->user()->can('view', $sermonService->getSermon());
23
        }
24
25
        return true;
26
    }
27
28
    /**
29
     * Get the validation rules that apply to the request.
30
     *
31
     * @return array
32
     */
33
    public function rules()
34
    {
35
        return [];
36
    }
37
38
    public function failedAuthorization()
39
    {
40
        throw new AuthorizationException('You are not allowed to transact on this sermon.');
41
    }
42
}
43