Completed
Branch master (75e1cb)
by Gabriel
04:26 queued 01:51
created

ErrorHandler::__invoke()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 18
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 15
cp 0
rs 8.2222
c 0
b 0
f 0
cc 7
eloc 15
nc 7
nop 1
crap 56
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\EmailNotConfirmedException;
9
use Waredesk\Exceptions\InvalidClientException;
10
use Waredesk\Exceptions\InvalidRequestException;
11
use Waredesk\Exceptions\UnknownException;
12
13
class ErrorHandler
14
{
15
    public function __invoke(array $error)
16
    {
17
        switch ($error['error']) {
18
            case 'invalid_request':
19
                throw new InvalidRequestException($error['message']);
20
            case 'account_banned':
21
                throw new AccountBannedException($error['message']);
22
            case 'account_deleted':
23
                throw new AccountDeletedException($error['message']);
24
            case 'account_invalid':
25
                throw new AccountInvalidException($error['message']);
26
            case 'email_not_confirmed':
27
                throw new EmailNotConfirmedException($error['message']);
28
            case 'invalid_client':
29
                throw new InvalidClientException($error['message']);
30
        }
31
        throw new UnknownException();
32
    }
33
}
34