UpdateRequest::failedAuthorization()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace FaithGen\Messages\Http\Requests;
4
5
use FaithGen\Messages\MessageService;
6
use FaithGen\SDK\Helpers\Helper;
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
     * @return bool
16
     */
17
    public function authorize(MessageService $messageService)
18
    {
19
        return $messageService->getMessage()
20
            && $this->user()->can('update', $messageService->getMessage());
21
    }
22
23
    /**
24
     * Get the validation rules that apply to the request.
25
     *
26
     * @return array
27
     */
28
    public function rules()
29
    {
30
        return [
31
            'title' => 'required|string',
32
            'message' => 'required|string|max:1500',
33
            'message_id' => Helper::$idValidation,
34
        ];
35
    }
36
37
    public function failedAuthorization()
38
    {
39
        throw new AuthorizationException('You do not have access to this message');
40
    }
41
}
42