Connector   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 13
c 1
b 0
f 0
dl 0
loc 41
ccs 12
cts 12
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handleErrors() 0 18 6
1
<?php
2
3
namespace GloBee\PaymentApi\Connectors;
4
5
use GloBee\PaymentApi\Exceptions\Http\AuthenticationException;
6
use GloBee\PaymentApi\Exceptions\Http\ForbiddenException;
7
use GloBee\PaymentApi\Exceptions\Http\HttpException;
8
use GloBee\PaymentApi\Exceptions\Http\NotFoundException;
9
use GloBee\PaymentApi\Exceptions\Http\ServerErrorException;
10
use GloBee\PaymentApi\Exceptions\Validation\ValidationException;
11
12
abstract class Connector
13
{
14
    /**
15
     * @param string $uri
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
16
     *
17
     * @return array
18
     */
19
    abstract public function getJson($uri);
0 ignored issues
show
Coding Style introduced by
Type hint "string" missing for $uri
Loading history...
20
21
    /**
22
     * @param string $uri
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
23
     * @param array  $data
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter comment
Loading history...
24
     *
25
     * @return array
26
     */
27
    abstract public function postJson($uri, array $data);
0 ignored issues
show
Coding Style introduced by
Type hint "string" missing for $uri
Loading history...
28
29
    /**
0 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$code" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$body" missing
Loading history...
30
     * @param $code
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
31
     * @param $body
0 ignored issues
show
Coding Style introduced by
Missing parameter name
Loading history...
32
     *
33
     * @throws \GloBee\PaymentApi\Exceptions\Http\HttpException;
0 ignored issues
show
Coding Style introduced by
Comment missing for @throws tag in function comment
Loading history...
34
     */
0 ignored issues
show
Coding Style Documentation introduced by
Missing @return tag in function comment
Loading history...
35 6
    protected function handleErrors($code, $body)
0 ignored issues
show
Coding Style introduced by
Type hint "code" missing for
Loading history...
Coding Style introduced by
Type hint "body" missing for
Loading history...
36
    {
37
        switch ($code) {
38 6
            case 401:
39 1
                throw new AuthenticationException();
40 5
            case 403:
41 1
                throw new ForbiddenException();
42 4
            case 404:
43 1
                throw new NotFoundException();
44 3
            case 422:
45 1
                throw new ValidationException(json_decode($body, true)['errors']);
46
        }
47
48 2
        if ($code >= 500) {
49 1
            throw new ServerErrorException();
50
        }
51
52 1
        throw new HttpException('Unknown HTTP exception', $code);
53
    }
54
}
55