CreateRequest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A failedAuthorization() 0 3 1
A authorize() 0 3 1
A rules() 0 11 1
1
<?php
2
3
namespace FaithGen\Sermons\Http\Requests;
4
5
use FaithGen\Sermons\Models\Sermon;
6
use FaithGen\Sermons\SermonHelper;
7
use Illuminate\Auth\Access\AuthorizationException;
8
use Illuminate\Foundation\Http\FormRequest;
9
10
class CreateRequest extends FormRequest
11
{
12
    /**
13
     * Determine if the user is authorized to make this request.
14
     *
15
     * @return bool
16
     */
17
    public function authorize()
18
    {
19
        return $this->user()->can('create', Sermon::class);
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
            'title' => SermonHelper::$titleValidation,
31
            'preacher' => SermonHelper::$titleValidation,
32
            'main_verses' => 'required|array',
33
            'date' => 'required|date',
34
            'reference_verses' => 'array',
35
            'sermon' => 'required|string|min:50',
36
            'resource' => 'sometimes|url',
37
            'image' => 'base64image',
38
        ];
39
    }
40
41
    protected function failedAuthorization()
42
    {
43
        throw new AuthorizationException('You can`t create more than 2 sermons when in free subscription mode, consider upgrading');
44
    }
45
}
46