ExceptionFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 32
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B createThrowable() 0 24 5
1
<?php
2
namespace KWTClient\Exception;
3
4
use GuzzleHttp\Exception\ClientException;
5
6
class ExceptionFactory
7
{
8
    /**
9
     * @param ClientException $clientException
10
     *
11
     * @return ApiException | SearchLimitException
12
     */
13
    public static function createThrowable(ClientException $clientException)
14
    {
15
        $data = \GuzzleHttp\json_decode($clientException->getResponse()->getBody()->getContents());
16
17
        $code = 0;
18
        $message = '';
19
20
        if (!empty($data->error)) {
21
            $error = $data->error;
22
            if (!empty($error->code)) {
23
                $code = $error->code;
24
            }
25
26
            if (!empty($error->message)) {
27
                $message = $error->message;
28
            }
29
        }
30
31
        if ($code == SearchLimitException::EXCEPTION_CODE) {
32
            return new SearchLimitException($message);
33
        }
34
        
35
        return new ApiException($message, $code);
36
    }
37
}
38