GetClassifiersRequest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
c 2
b 0
f 1
lcom 1
cbo 7
dl 0
loc 50
ccs 23
cts 23
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getData() 0 10 2
B sendData() 0 27 4
1
<?php
2
3
namespace Bobbyshaw\WatsonVisualRecognition\Message;
4
5
use Bobbyshaw\WatsonVisualRecognition\Exceptions\AuthException;
6
use GuzzleHttp\Exception\ClientException;
7
use GuzzleHttp\Psr7\Request;
8
9
/**
10
 * Class GetClassifiersRequest
11
 * @package Bobbyshaw\WatsonVisualRecognition\Message
12
 */
13
class GetClassifiersRequest extends AbstractRequest
14
{
15
    const CLASSIFIERS_PATH = 'classifiers/';
16
    
17 8
    public function getData()
18
    {
19 8
        $data = parent::getData();
20
21 8
        if ($verbose = $this->getVerbose()) {
22 2
            $data['verbose'] = $verbose;
23 2
        }
24
25 8
        return $data;
26
    }
27
28
    /**
29
     * Send HTTP request to get list of classifiers
30
     *
31
     * @param array $data
32
     * @return ClassifiersResponse
33
     * @throws AuthException
34
     */
35 7
    public function sendData($data)
36
    {
37 7
        $query = ['version' => $data['version']];
38
39 7
        if (isset($data['verbose'])) {
40 2
            $query['verbose'] = $data['verbose'];
41 2
        }
42
43 7
        $request = new Request(
44 7
            'GET',
45 7
            $this->getApiUrl(static::CLASSIFIERS_PATH) . '?' . http_build_query($query),
46 7
            ['Authorization' => 'Basic ' . base64_encode($data['username'] . ':' . $data['password'])]
47 7
        );
48
49 7
        $this->response = null;
50
51
        try {
52 7
            $response = $this->httpClient->send($request);
53 6
            $this->response = new ClassifiersResponse($this, $response->getBody());
54 7
        } catch (ClientException $e) {
55 1
            if ($e->getCode() == 401) {
56 1
                throw new AuthException('Invalid credentials provided');
57
            }
58
        }
59
60 6
        return $this->response;
61
    }
62
}
63