UpdateRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A failedAuthorization() 0 3 1
A authorize() 0 4 2
A rules() 0 12 1
1
<?php
2
3
namespace Innoflash\Events\Http\Requests;
4
5
use Illuminate\Auth\Access\AuthorizationException;
6
use Illuminate\Foundation\Http\FormRequest;
7
use Innoflash\Events\Services\EventsService;
8
9
class UpdateRequest extends FormRequest
10
{
11
    /**
12
     * Determine if the user is authorized to make this request.
13
     *
14
     * @return bool
15
     */
16
    public function authorize(EventsService $eventsService)
17
    {
18
        return $eventsService->getEvent()
19
            && $this->user()->can('update', $eventsService->getEvent());
20
    }
21
22
    /**
23
     * Get the validation rules that apply to the request.
24
     *
25
     * @return array
26
     */
27
    public function rules()
28
    {
29
        return [
30
            'name'        => 'required|string',
31
            'description' => 'required|string',
32
            'location'    => 'required|array',
33
            'start'       => 'required|date_format:Y-m-d H:i',
34
            'end'         => 'required|date_format:Y-m-d H:i',
35
            'published'   => 'required|boolean',
36
            'url'         => 'url',
37
            'video_url'   => 'url',
38
            'banner'      => 'base64image',
39
        ];
40
    }
41
42
    public function failedAuthorization()
43
    {
44
        throw new AuthorizationException('You are not allowed to update this event');
45
    }
46
}
47