Completed
Push — master ( c915d2...2ad4b2 )
by Alexander
04:32
created

ThrowsApiErrors   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A failedValidation() 0 4 1
A failedAuthorization() 0 4 1
1
<?php
2
3
namespace Flugg\Responder\Traits;
4
5
use Illuminate\Contracts\Validation\Validator;
6
use Flugg\Responder\Exceptions\UnauthorizedException;
7
use Flugg\Responder\Exceptions\ValidationFailedException;
8
9
10
/**
11
 * Use this trait in your base form request to override the exceptions thrown when
12
 * validation or authorization fails. This allows the package to render proper
13
 * API responses through the HandlesApiErrors trait.
14
 *
15
 * @package Laravel Responder
16
 * @author  Alexander Tømmerås <[email protected]>
17
 * @license The MIT License
18
 */
19
trait ThrowsApiErrors
20
{
21
    /**
22
     * Handle a failed validation attempt.
23
     *
24
     * @param  \Illuminate\Contracts\Validation\Validator $validator
25
     * @return void
26
     * @throws ValidationFailedException
27
     */
28
    protected function failedValidation( Validator $validator )
29
    {
30
        throw new ValidationFailedException( $validator );
31
    }
32
33
    /**
34
     * Handle a failed authorization attempt.
35
     *
36
     * @return void
37
     * @throws UnauthorizedException
38
     */
39
    protected function failedAuthorization()
40
    {
41
        throw new UnauthorizedException();
42
    }
43
}