CreateRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 33
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 3 1
A rules() 0 5 1
A failedAuthorization() 0 8 2
1
<?php
2
3
namespace FaithGen\Gallery\Http\Requests;
4
5
use FaithGen\Gallery\Models\Album;
6
use Illuminate\Auth\Access\AuthorizationException;
7
use Illuminate\Foundation\Http\FormRequest;
8
9
class CreateRequest extends FormRequest
10
{
11
    /**
12
     * Determine if the user is authorized to make this request.
13
     *
14
     * @return bool
15
     */
16
    public function authorize()
17
    {
18
        return $this->user()->can('create', Album::class);
19
    }
20
21
    /**
22
     * Get the validation rules that apply to the request.
23
     *
24
     * @return array
25
     */
26
    public function rules()
27
    {
28
        return [
29
            'name' => 'required|string|max:100',
30
            'description' => 'required|string',
31
        ];
32
    }
33
34
    protected function failedAuthorization()
35
    {
36
        if (strcmp(auth()->user()->account->level, 'Free') === 0) {
37
            $message = 'You need to upgrade to able to create more than one album this month';
38
        } else {
39
            $message = 'You need to upgrade further to be able to create more than 5 albums this month';
40
        }
41
        throw new AuthorizationException($message, 403);
42
    }
43
}
44