Completed
Push — master ( 87c3bc...92328c )
by Márk
01:55
created

HttpAsyncClientEmulator::sendAsyncRequest()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4286
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Http\Client\Common;
4
5
use Http\Client\Exception;
6
use Http\Promise;
7
use Psr\Http\Message\RequestInterface;
8
9
/**
10
 * Emulates an HTTP Async Client in an HTTP Client.
11
 *
12
 * @author Márk Sági-Kazár <[email protected]>
13
 */
14
trait HttpAsyncClientEmulator
15
{
16
    /**
17
     * {@inheritdoc}
18
     *
19
     * @see HttpClient::sendRequest
20
     */
21
    abstract public function sendRequest(RequestInterface $request);
22
23
    /**
24
     * {@inheritdoc}
25
     *
26
     * @see HttpAsyncClient::sendAsyncRequest
27
     */
28 2
    public function sendAsyncRequest(RequestInterface $request)
29
    {
30
        try {
31 2
            return new Promise\FulfilledPromise($this->sendRequest($request));
32 1
        } catch (Exception $e) {
33 1
            return new Promise\RejectedPromise($e);
0 ignored issues
show
Documentation introduced by
$e is of type object<Http\Client\Exception>, but the function expects a object<Exception>.

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...
34
        }
35
    }
36
}
37