UpdateRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 36
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 10 1
A authorize() 0 4 2
A failedAuthorization() 0 3 1
1
<?php
2
3
namespace FaithGen\Sermons\Http\Requests;
4
5
use FaithGen\Sermons\SermonHelper;
6
use FaithGen\Sermons\SermonService;
7
use Illuminate\Auth\Access\AuthorizationException;
8
use Illuminate\Foundation\Http\FormRequest;
9
10
class UpdateRequest 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
        return $sermonService->getSermon()
22
            && $this->user()->can('update', $sermonService->getSermon());
23
    }
24
25
    /**
26
     * Get the validation rules that apply to the request.
27
     *
28
     * @return array
29
     */
30
    public function rules()
31
    {
32
        return [
33
            'title'            => SermonHelper::$titleValidation,
34
            'preacher'         => SermonHelper::$titleValidation,
35
            'main_verses'      => 'required|array',
36
            'date'             => 'required|date',
37
            'reference_verses' => 'array',
38
            'sermon'           => 'required|string|min:50',
39
            'resource'         => 'sometimes|url',
40
        ];
41
    }
42
43
    protected function failedAuthorization()
44
    {
45
        throw new AuthorizationException('You can`t edit a sermon that you do not own');
46
    }
47
}
48