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

ErrorHandler::__invoke()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 20
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 10.8127

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 11
cts 17
cp 0.6471
rs 7.7777
c 0
b 0
f 0
cc 8
eloc 17
nc 8
nop 1
crap 10.8127
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