GetClassifierRequest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 7
dl 0
loc 44
ccs 18
cts 18
cp 1
rs 10

2 Methods

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