Completed
Push — master ( 1fdaf4...134b2d )
by Gabriel
02:42
created

ErrorHandler   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Test Coverage

Coverage 64.71%

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 8
dl 0
loc 23
ccs 11
cts 17
cp 0.6471
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 20 8
1
<?php
2
3
namespace Waredesk;
4
5
use Waredesk\Exceptions\AccountBannedException;
6
use Waredesk\Exceptions\AccountDeletedException;
7
use Waredesk\Exceptions\AccountInvalidException;
8
use Waredesk\Exceptions\AuthenticationErrorException;
9
use Waredesk\Exceptions\EmailNotConfirmedException;
10
use Waredesk\Exceptions\InvalidClientException;
11
use Waredesk\Exceptions\InvalidRequestException;
12
use Waredesk\Exceptions\UnknownException;
13
14
class ErrorHandler
15
{
16 2
    public function __invoke(array $error)
17
    {
18 2
        switch ($error['error']) {
19 2
            case 'authentication_error':
20
                throw new AuthenticationErrorException($error['message']);
21 2
            case 'invalid_request':
22 1
                throw new InvalidRequestException($error['message'], $error['errors']);
23 1
            case 'account_banned':
24
                throw new AccountBannedException($error['message']);
25 1
            case 'account_deleted':
26
                throw new AccountDeletedException($error['message']);
27 1
            case 'account_invalid':
28
                throw new AccountInvalidException($error['message']);
29 1
            case 'email_not_confirmed':
30
                throw new EmailNotConfirmedException($error['message']);
31 1
            case 'invalid_client':
32 1
                throw new InvalidClientException($error['message']);
33
        }
34
        throw new UnknownException();
35
    }
36
}
37