CreateRequest::authorize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Innoflash\Events\Http\Requests;
4
5
use Illuminate\Auth\Access\AuthorizationException;
6
use Illuminate\Foundation\Http\FormRequest;
7
use Innoflash\Events\Models\Event;
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 true;
19
20
        return $this->user()->can('create', Event::class);
0 ignored issues
show
Unused Code introduced by
return $this->user()->ca...ts\Models\Event::class) is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
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
            'name' => 'required|string',
32
            'description' => 'required|string',
33
            'location' => 'array',
34
            'start' => 'required|date_format:Y-m-d H:i',
35
            'end' => 'required|date_format:Y-m-d H:i',
36
            'published' => 'required|boolean',
37
            'url' => 'url',
38
            'video_url' => 'url',
39
            'banner' => 'base64image',
40
        ];
41
    }
42
43
    protected function failedAuthorization()
44
    {
45
        if (strcmp(auth()->user()->account->level, 'Free') === 0) {
46
            throw new AuthorizationException('You need to upgrade to able to create events');
47
        }
48
    }
49
}
50