Passed
Push — master ( a67e0e...5a6b87 )
by Vladislav
09:14 queued 07:10
created

PostRequest::buildRequestParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Carpenstar\ByBitAPI\Core\Request;
4
5
use Carpenstar\ByBitAPI\Core\Enums\EnumHttpMethods;
6
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseHandlerInterface;
7
8
class PostRequest extends Curl
9
{
10
    /**
11
     * @param string $endpoint
12
     * @param array $params
13
     * @return IResponseHandlerInterface
14
     */
15
    public function execute(string $endpoint, array $params): array
16
    {
17
        $bodyParams = $this->buildRequestParams($params);
18
19
        $this->addCurlOpt(CURLOPT_URL, "{$this->credentials->getHost()}{$endpoint}")
20
             ->addCurlOpt(CURLOPT_CUSTOMREQUEST, EnumHttpMethods::POST)
21
             ->addCurlOpt(CURLOPT_ENCODING, '')
22
             ->addCurlOpt(CURLOPT_MAXREDIRS, 10)
23
             ->addCurlOpt(CURLOPT_TIMEOUT, 0)
24
             ->addCurlOpt(CURLOPT_FOLLOWLOCATION, true)
25
             ->addCurlOpt(CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1)
26
             ->addCurlOpt(CURLOPT_POSTFIELDS, $bodyParams);
27
28
        $this->auth($bodyParams);
29
30
        return $this->query();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->query() returns the type array which is incompatible with the documented return type Carpenstar\ByBitAPI\Core...esponseHandlerInterface.
Loading history...
31
    }
32
33
    /**
34
     * @param array $queryParams
35
     * @return string|null
36
     */
37
    private function buildRequestParams(array $queryParams): ?string
38
    {
39
        return json_encode($queryParams);
40
    }
41
}
42