ImagesRequest::authorize()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 4
rs 10
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 ImagesRequest 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 $albumService->getAlbum()
21
            && $this->user()->can('view', $albumService->getAlbum());
22
    }
23
24
    /**
25
     * Get the validation rules that apply to the request.
26
     *
27
     * @return array
28
     */
29
    public function rules()
30
    {
31
        return [
32
            'limit'       => 'integer|min:1',
33
            'filter_text' => 'sometimes:string',
34
        ];
35
    }
36
37
    public function failedAuthorization()
38
    {
39
        throw new AuthorizationException('You are not allowed to view this album');
40
    }
41
}
42