Passed
Pull Request — master (#22)
by Vladislav
02:38
created

BybitAPI   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 15
c 1
b 0
f 0
dl 0
loc 73
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A publicEndpoint() 0 4 1
A rest() 0 3 1
A privateEndpoint() 0 6 1
A __construct() 0 12 4
A websocket() 0 3 1
1
<?php
2
namespace Carpenstar\ByBitAPI;
3
4
use Carpenstar\ByBitAPI\Core\Auth\Credentials;
5
use Carpenstar\ByBitAPI\Core\Enums\EnumOutputMode;
6
use Carpenstar\ByBitAPI\Core\Exceptions\ApiException;
7
use Carpenstar\ByBitAPI\Core\Exceptions\SDKException;
8
use Carpenstar\ByBitAPI\Core\Builders\RestBuilder;
9
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseInterface;
10
use Carpenstar\ByBitAPI\Core\Interfaces\ISuccessCurlResponseDtoInterface;
11
use Carpenstar\ByBitAPI\Core\Interfaces\IParametersInterface;
12
use Carpenstar\ByBitAPI\WebSockets\Builders\WebSocketsBuilder;
0 ignored issues
show
Bug introduced by
The type Carpenstar\ByBitAPI\WebS...lders\WebSocketsBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Carpenstar\ByBitAPI\WebSockets\Objects\Channels\Interfaces\IChannelHandlerInterface;
0 ignored issues
show
Bug introduced by
The type Carpenstar\ByBitAPI\WebS...ChannelHandlerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Carpenstar\ByBitAPI\WebSockets\Objects\WebSockets\Interfaces\IWebSocketArgumentInterface;
0 ignored issues
show
Bug introduced by
The type Carpenstar\ByBitAPI\WebS...SocketArgumentInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
16
class BybitAPI
17
{
18
    /**
19
     * @param string $host
20
     * @param string $apiKey
21
     * @param string $secret
22
     */
23
    public function __construct(string $host = null, string $apiKey = null, string $secret = null)
24
    {
25
        if (!empty($host)) {
26
            Credentials::setHost($host);
27
        }
28
29
        if (!empty($apiKey)) {
30
            Credentials::setApiKey($apiKey);
31
        }
32
33
        if (!empty($secret)) {
34
            Credentials::setSecret($secret);
35
        }
36
    }
37
38
    /**
39
     * @param string $endpointClassName
40
     * @param IParametersInterface|null $parameters
41
     * @param int|null $resultMode
42
     * @return ISuccessCurlResponseDtoInterface
43
     * @throws SDKException
44
     */
45
    public function rest(string $endpointClassName, ?IParametersInterface $parameters = null): IResponseInterface
46
    {
47
        return RestBuilder::make($endpointClassName, $parameters)->execute();
0 ignored issues
show
Bug Best Practice introduced by
The expression return Carpenstar\ByBitA...$parameters)->execute() returns the type Carpenstar\ByBitAPI\Core...aces\IResponseInterface which is incompatible with the documented return type Carpenstar\ByBitAPI\Core...urlResponseDtoInterface.
Loading history...
48
    }
49
50
    /**
51
     * @param string $host
52
     * @param string $endpointClassName
53
     * @param IParametersInterface|null $parameters
54
     * @return IResponseInterface
55
     * @throws SDKException
56
     */
57
    public function publicEndpoint(string $host, string $endpointClassName, ?IParametersInterface $parameters = null): IResponseInterface
58
    {
59
        Credentials::setHost($host);
60
        return $this->rest($endpointClassName, $parameters);
61
    }
62
63
    /**
64
     * @param string $host
65
     * @param string $apiKey
66
     * @param string $secret
67
     * @param string $endpointClassName
68
     * @param IParametersInterface|null $parameters
69
     * @return IResponseInterface
70
     * @throws SDKException
71
     */
72
    public function privateEndpoint(string $host, string $apiKey, string $secret, string $endpointClassName, ?IParametersInterface $parameters = null): IResponseInterface
73
    {
74
        Credentials::setHost($host);
75
        Credentials::setApiKey($apiKey);
76
        Credentials::setSecret($secret);
77
        return $this->rest($endpointClassName, $parameters);
78
    }
79
80
    /**
81
     * @param string $webSocketChannelClassName
82
     * @param array $data
83
     * @return void
84
     * @throws \Exception
85
     */
86
    public function websocket(string $webSocketChannelClassName, IWebSocketArgumentInterface $data, IChannelHandlerInterface $channelHandler, int $mode = EnumOutputMode::MODE_ENTITY, int $wsClientTimeout = IWebSocketArgumentInterface::DEFAULT_SOCKET_CLIENT_TIMEOUT): void
87
    {
88
        WebSocketsBuilder::make($webSocketChannelClassName, $data, $channelHandler, $mode, $wsClientTimeout)->execute();
89
    }
90
}
91
92