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
|
|||
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 |
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
orexit
statements that have been added for debug purposes.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.