AddImagesRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A failedAuthorization() 0 8 2
A rules() 0 4 1
A authorize() 0 3 1
1
<?php
2
3
namespace FaithGen\Gallery\Http\Requests;
4
5
use FaithGen\Gallery\Services\AlbumService;
6
use Illuminate\Auth\Access\AuthorizationException;
7
use Illuminate\Foundation\Http\FormRequest;
8
9
class AddImagesRequest extends FormRequest
10
{
11
    /**
12
     * Determine if the user is authorized to make this request.
13
     *
14
     * @param  \FaithGen\Gallery\Services\AlbumService  $albumService
15
     *
16
     * @return bool
17
     */
18
    public function authorize(AlbumService $albumService)
19
    {
20
        return $this->user()->can('addImages', $albumService->getAlbum());
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
            'images' => 'required|image',
32
            // 'images' => 'required|array',
33
            // 'images.*' => 'required|base64image',
34
        ];
35
    }
36
37
    protected function failedAuthorization()
38
    {
39
        if (strcmp(auth()->user()->account->level, 'Free') === 0) {
40
            $message = 'You need to upgrade to able to add more than 10 images to this album month';
41
        } else {
42
            $message = 'You need to upgrade to able to add more than 20 images to this album month';
43
        }
44
        throw new AuthorizationException($message, 403);
45
    }
46
}
47