Completed
Push — develop ( 86f0dd...f71342 )
by Adam
12s
created

ToneRequest::sendData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 9
cts 9
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * Tone Request class
4
 */
5
6
namespace IBM\Watson\ToneAnalyzer\Message;
7
8
use GuzzleHttp\Exception\ClientException;
9
use GuzzleHttp\Psr7\Request;
10
11
/**
12
 * Tone Request class
13
 *
14
 * This request class provides the required functions to
15
 * interact with the IBM Watson Tone Analyzer service
16
 *
17
 * @see AbstractRequest
18
 */
19
class ToneRequest extends AbstractRequest
20
{
21
    /**
22
     * Get request data
23
     *
24
     * @return array
25
     */
26 6
    public function getData()
27
    {
28 6
        $data = parent::getData();
29 6
        $data['version'] = $this->getVersion();
30 6
        $data['text'] = $this->getText();
31
32 6
        return $data;
33
    }
34
35
    /**
36
     * Send request data
37
     *
38
     * @param array $data
39
     * @return ToneResponse
40
     */
41 3
    public function sendData($data)
42
    {
43 3
        $request = new Request(
44 3
            'GET',
45 3
            $this->endpoint . '?' . http_build_query(['version' => $this->getVersion(), 'text' => $this->getText()]),
46 3
            ['Authorization' => 'Basic ' . base64_encode($data['username'] . ':' . $data['password'])]
47 2
        );
48
49
        try {
50 3
            $response = $this->httpClient->send($request);
0 ignored issues
show
Documentation introduced by
$request is of type object<GuzzleHttp\Psr7\Request>, but the function expects a array|object<Guzzle\Http...ssage\RequestInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
51 2
        } catch (ClientException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
52
        }
53
54 3
        return $this->response = new ToneResponse($this, $response->getBody());
0 ignored issues
show
Documentation Bug introduced by
It seems like new \IBM\Watson\ToneAnal..., $response->getBody()) of type object<IBM\Watson\ToneAn...r\Message\ToneResponse> is incompatible with the declared type object<Omnipay\Common\Message\ResponseInterface> of property $response.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
55
    }
56
}
57