Passed
Pull Request — develop (#23)
by Adam
01:31
created

Tone::analyze()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace IBM\Watson\ToneAnalyzer\Api;
6
7
use IBM\Watson\Common\Api\AbstractApi;
8
use IBM\Watson\ToneAnalyzer\Model\DocumentAnalysis;
9
10
/**
11
 * Tone is used to interact with the "General tone" API endpoint.
12
 */
13
class Tone extends AbstractApi
14
{
15
    const API_ENDPOINT = '/tone';
16
    const PARAM_TEXT = 'text';
17
18
    /**
19
     * @param string $text   Text to analyze.
20
     * @param array  $params Query parameters.
21
     *
22
     * @return mixed
23
     * @throws \Http\Client\Exception
24
     */
25
    public function analyze(string $text, array $params = [])
26
    {
27
        $params[self::PARAM_TEXT] = $text;
28
29
        $response = $this->post(self::API_ENDPOINT, $params);
30
31
        if (200 !== $response->getStatusCode()) {
32
            $this->handleErrors($response);
33
        }
34
35
        return $this->hydrator->hydrate($response, DocumentAnalysis::class);
36
    }
37
}
38