Completed
Branch 3.0 (ea0c88)
by Brian
11:51
created

AriClientAware::processRequestException()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 6.4222

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 14
ccs 8
cts 13
cp 0.6153
rs 8.8571
cc 5
eloc 12
nc 5
nop 1
crap 6.4222
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\InvalidParameterException;
24
use phparia\Exception\NotFoundException;
25
use phparia\Exception\UnprocessableEntityException;
26
27
/**
28
 * @author Brian Smith <[email protected]>
29
 */
30
abstract class AriClientAware implements AriClientAwareInterface
31
{
32
    /**
33
     * @var AriClient
34
     */
35
    protected $client;
36
37 80
    public function __construct(AriClient $client)
38
    {
39 80
        $this->client = $client;
40 80
    }
41
42
    /**
43
     * @return AriClient
44
     */
45
    public function getClient()
46
    {
47
        return $this->client;
48
    }
49
50
    /**
51
     * @todo This doesn't really belong here
52
     * @param RequestException $e
53
     * @throws ConflictException
54
     * @throws InvalidParameterException
55
     * @throws NotFoundException
56
     * @throws UnprocessableEntityException
57
     */
58 25
    protected function processRequestException(RequestException $e) {
59 25
        switch ($e->getCode()) {
60 25
            case 400: // Missing parameter
61 7
                throw new InvalidParameterException($e);
62 18
            case 404: // Does not exist
63 16
                throw new NotFoundException($e);
64 2
            case 409:
65 2
                throw new ConflictException($e);
66
            case 422:
67
                throw new UnprocessableEntityException($e);
68
            default:
69
                throw $e;
70
        }
71
    }
72
}
73