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

Tone   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A analyze() 0 11 2
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