ConverseApi   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 46
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A converse() 0 21 4
1
<?php
2
3
namespace Tgallice\Wit;
4
5
use Tgallice\Wit\Model\Context;
6
7
class ConverseApi
8
{
9
    use ResponseHandler;
10
11
    /**
12
     * @var Client
13
     */
14
    private $client;
15
16
    /**
17
     * @param Client $client
18
     */
19 5
    public function __construct(Client $client)
20
    {
21 5
        $this->client = $client;
22 5
    }
23
24
    /**
25
     * @param string $sessionId
26
     * @param string|null $text
27
     * @param Context|null $context
28
     *
29
     * @return array
30
     */
31 2
    public function converse($sessionId, $text = null, Context $context = null)
32
    {
33
        $query = [
34 2
            'session_id' => $sessionId,
35 2
        ];
36
37 2
        if (!empty($text)) {
38 2
            $query['q'] = $text;
39 2
        }
40
41 2
        $body = null;
42
43
        // Don't send empty array
44 2
        if (null !== $context && !$context->isEmpty()) {
45 1
            $body = $context;
46 1
        }
47
48 2
        $response = $this->client->send('POST', '/converse', $body, $query);
49
50 2
        return $this->decodeResponse($response);
51
    }
52
}
53