CommentRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 5 1
A authorize() 0 4 2
A failedAuthorization() 0 3 1
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 CommentRequest 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('view', $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
            'message_id' => Helper::$idValidation,
32
            'comment' => 'required|string',
33
        ];
34
    }
35
36
    public function failedAuthorization()
37
    {
38
        throw new AuthorizationException('You do not have access to this message');
39
    }
40
}
41