|
1
|
|
|
<?php |
|
2
|
|
|
namespace Carpenstar\ByBitAPI\Core\Endpoints; |
|
3
|
|
|
|
|
4
|
|
|
use Carpenstar\ByBitAPI\Core\Enums\EnumHttpMethods; |
|
5
|
|
|
use Carpenstar\ByBitAPI\Core\Enums\EnumOutputMode; |
|
6
|
|
|
use Carpenstar\ByBitAPI\Core\Exceptions\ApiException; |
|
7
|
|
|
use Carpenstar\ByBitAPI\Core\Interfaces\IEndpointInterface; |
|
8
|
|
|
use Carpenstar\ByBitAPI\Core\Interfaces\IParametersInterface; |
|
9
|
|
|
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseInterface; |
|
10
|
|
|
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse; |
|
11
|
|
|
use Carpenstar\ByBitAPI\Core\Objects\StubQueryBag; |
|
12
|
|
|
use Carpenstar\ByBitAPI\Core\Request\Curl; |
|
13
|
|
|
use Carpenstar\ByBitAPI\Core\Request\GetRequest; |
|
14
|
|
|
use Carpenstar\ByBitAPI\Core\Request\PostRequest; |
|
15
|
|
|
use Carpenstar\ByBitAPI\Spot\Trade\PlaceOrder\PlaceOrder; |
|
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
abstract class Endpoint implements IEndpointInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var string HTTP-метод GET, POST и т.д |
|
21
|
|
|
*/ |
|
22
|
|
|
protected string $method; |
|
23
|
|
|
protected string $url; |
|
24
|
|
|
protected int $resultMode; |
|
25
|
|
|
protected IParametersInterface $requestParameters; |
|
26
|
|
|
|
|
27
|
|
|
protected $response; |
|
28
|
|
|
|
|
29
|
|
|
abstract protected function getResponseClassname(): string; |
|
30
|
|
|
abstract protected function getRequestClassname(): string; |
|
31
|
|
|
abstract protected function getEndpointUrl(): string; |
|
32
|
|
|
|
|
33
|
|
|
public function setResultMode(int $resultMode): self |
|
34
|
|
|
{ |
|
35
|
|
|
$this->resultMode = $resultMode; |
|
36
|
|
|
return $this; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param IParametersInterface $options |
|
41
|
|
|
* @return $this |
|
42
|
|
|
* @throws ApiException |
|
43
|
|
|
*/ |
|
44
|
|
|
public function bindRequestParameters(?IParametersInterface $requestParameters): self |
|
45
|
|
|
{ |
|
46
|
|
|
if (get_class($requestParameters ?? new StubQueryBag()) != $this->getRequestClassname()) { |
|
47
|
|
|
throw new ApiException(get_class($requestParameters) . " must be instance of " . $this->getRequestClassname()); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$this->requestParameters = $requestParameters ?? new StubQueryBag(); |
|
51
|
|
|
return $this; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function execute(): IResponseInterface |
|
55
|
|
|
{ |
|
56
|
|
|
switch (static::HTTP_METHOD) { |
|
|
|
|
|
|
57
|
|
|
case EnumHttpMethods::GET: |
|
58
|
|
|
$request = GetRequest::getInstance(static::IS_NEED_AUTHORIZATION); |
|
|
|
|
|
|
59
|
|
|
break; |
|
60
|
|
|
case EnumHttpMethods::POST: |
|
61
|
|
|
$request = PostRequest::getInstance(static::IS_NEED_AUTHORIZATION); |
|
62
|
|
|
break; |
|
63
|
|
|
default: |
|
64
|
|
|
throw new \Exception("Http Method not detected"); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
$response = $request |
|
68
|
|
|
->exec( |
|
69
|
|
|
$this->getEndpointUrl(), |
|
70
|
|
|
$this->requestParameters->fetchArray() |
|
71
|
|
|
)->bindEntity( |
|
72
|
|
|
static::getResponseClassname() |
|
|
|
|
|
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
return $response->handle($this->resultMode); |
|
76
|
|
|
} |
|
77
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths