Completed
Push — develop ( 5fc40e...dcac96 )
by Adam
13s
created

ToneChat::analyze()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.009

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 9
cts 10
cp 0.9
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 4
nop 2
crap 3.009
1
<?php
2
3
namespace IBM\Watson\ToneAnalyzer\Api;
4
5
use IBM\Watson\Common\Api\AbstractApi;
6
use IBM\Watson\ToneAnalyzer\Model\UtteranceAnalyses;
7
8
class ToneChat extends AbstractApi
9
{
10
    /**
11
     * Analyze tone chat
12
     *
13
     * @param string    $text
14
     * @param array     $params
15
     *
16
     * @return mixed
17
     */
18 6
    public function analyze($text, array $params = [])
19
    {
20 6
        $headers = ['Content-Type' => 'application/json'];
21
22 6
        if (!isset($params['version'])) {
23 6
            $params['version'] = \date('Y-m-d');
24 2
        }
25
26 6
        $response = $this->postRaw('/api/v3/tone_chat' . '?' . http_build_query($params), $text, $headers);
27
28 6
        if ($response->getStatusCode() !== 200) {
29 3
            $this->handleErrors($response);
30
        }
31
32 3
        return $this->hydrator->hydrate($response, UtteranceAnalyses::class);
33
    }
34
}
35