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

AriClientAware   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 61.11%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 7
c 2
b 0
f 2
lcom 0
cbo 5
dl 0
loc 43
ccs 11
cts 18
cp 0.6111
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getClient() 0 4 1
B processRequestException() 0 14 5
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