AbstractApi::sendRequest()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * A php library for using the Emarsys API.
5
 *
6
 * @link      https://github.com/quitoque/emarsys-php-client
7
 * @package   emarsys-php-client
8
 * @license   MIT
9
 * @copyright Copyright (c) 2017 Quitoque <[email protected]>
10
 */
11
12
namespace Emarsys\Api;
13
14
use Http\Client\Common\PluginClient;
15
use Http\Client\HttpAsyncClient;
16
use Http\Message\RequestFactory;
17
use Http\Promise\Promise;
18
use Psr\Http\Message\RequestInterface;
19
use Psr\Http\Message\ResponseInterface;
20
21
/**
22
 * Class AbstractApi.
23
 *
24
 * @author Claude Khedhiri <[email protected]>
25
 */
26
abstract class AbstractApi implements ApiInterface
27
{
28
    /**
29
     * @var HttpAsyncClient
30
     */
31
    private $httpClient;
32
33
    /**
34
     * @var RequestFactory
35
     */
36
    private $requestFactory;
37
38
    /**
39
     * AbstractApi constructor.
40
     *
41
     * @param PluginClient   $httpClient
42
     * @param RequestFactory $requestFactory
43
     */
44 2
    public function __construct(PluginClient $httpClient, RequestFactory $requestFactory)
45
    {
46 2
        $this->httpClient = $httpClient;
47 2
        $this->requestFactory = $requestFactory;
48 2
    }
49
50
    /**
51
     * @param string     $method
52
     * @param string     $uri
53
     * @param array      $headers
54
     * @param array|null $body
55
     *
56
     * @return RequestInterface
57
     */
58
    protected function createRequest($method, $uri, array $headers = array(), $body = null)
59
    {
60
        return $this->requestFactory->createRequest(
61
            $method,
62
            $uri,
63
            $headers,
64
            $body
0 ignored issues
show
Bug introduced by
It seems like $body defined by parameter $body on line 58 can also be of type array; however, Http\Message\RequestFactory::createRequest() does only seem to accept resource|string|object<P...e\StreamInterface>|null, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
65
        );
66
    }
67
68
    /**
69
     * @param RequestInterface $request
70
     *
71
     * @return ResponseInterface
72
     */
73
    protected function sendRequest(RequestInterface $request)
74
    {
75
        return $this->httpClient->sendRequest($request);
76
    }
77
78
    /**
79
     * @param RequestInterface $request
80
     *
81
     * @return Promise
82
     */
83
    protected function sendAsyncRequest(RequestInterface $request)
84
    {
85
        return $this->httpClient->sendAsyncRequest($request);
86
    }
87
}
88