AriClientAware::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * Copyright 2014 Brian Smith <[email protected]>.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *      http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace phparia\Client;
20
21
use GuzzleHttp\Exception\RequestException;
22
use phparia\Exception\ConflictException;
23
use phparia\Exception\ForbiddenException;
24
use phparia\Exception\InvalidParameterException;
25
use phparia\Exception\NotFoundException;
26
use phparia\Exception\PreconditionFailedException;
27
use phparia\Exception\ServerException;
28
use phparia\Exception\UnprocessableEntityException;
29
30
/**
31
 * @author Brian Smith <[email protected]>
32
 */
33
abstract class AriClientAware implements AriClientAwareInterface
34
{
35
    /**
36
     * @var AriClient
37
     */
38
    protected $client;
39
40 88
    public function __construct(AriClient $client)
41
    {
42 88
        $this->client = $client;
43 88
    }
44
45
    /**
46
     * @return AriClient
47
     */
48
    public function getClient()
49
    {
50
        return $this->client;
51
    }
52
53
    /**
54
     * @todo This doesn't really belong here
55
     * @param RequestException $e
56
     * @throws ConflictException
57
     * @throws PreconditionFailedException
58
     * @throws InvalidParameterException
59
     * @throws ForbiddenException
60
     * @throws NotFoundException
61
     * @throws UnprocessableEntityException
62
     * @throws ServerException
63
     */
64 9
    protected function processRequestException(RequestException $e) {
65 9
        switch ($e->getCode()) {
66 9
            case 400: // Missing parameter
67
                throw new InvalidParameterException($e);
68 9
            case 403: // Forbidden
69
                throw new ForbiddenException($e);
70 9
            case 404: // Does not exist
71
                throw new NotFoundException($e);
72 9
            case 409:
73
                throw new ConflictException($e);
74 9
            case 412:
75
                throw new PreconditionFailedException($e);
76 9
            case 422:
77
                throw new UnprocessableEntityException($e);
78 9
            case 500:
79
                throw new ServerException($e);
80 9
            default:
81 9
                throw $e;
82 9
        }
83
    }
84
}
85