Passed
Push — master ( 54c1b4...a67e0e )
by Vladislav
11:20 queued 09:15
created

BybitAPI::exception()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 0
c 1
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 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\SDKException;
7
use Carpenstar\ByBitAPI\Core\Builders\RestBuilder;
8
use Carpenstar\ByBitAPI\Core\Interfaces\IEndpointInterface;
9
use Carpenstar\ByBitAPI\Core\Interfaces\IResponseInterface;
10
use Carpenstar\ByBitAPI\Core\Interfaces\IParametersInterface;
11
use Carpenstar\ByBitAPI\Core\Objects\AbstractParameters;
12
use Carpenstar\ByBitAPI\Core\Request\Curl;
13
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...
14
use Carpenstar\ByBitAPI\WebSockets\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...
15
use Carpenstar\ByBitAPI\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...
16
17
class BybitAPI
18
{
19
    /**
20
     * @param string $host
21
     * @param string $apiKey
22
     * @param string $secret
23
     * @return $this
24
     */
25
    public function setCredentials(string $host, string $apiKey = '', string $secret = ''): self
26
    {
27
        Credentials::setHost($host);
28
        Credentials::setApiKey($apiKey);
29
        Credentials::setSecret($secret);
30
        return $this;
31
    }
32
33
    /**
34
     * @param string $host
35
     * @return $this
36
     */
37
    public function setHost(string $host): self
38
    {
39
        Credentials::setHost($host);
40
        return $this;
41
    }
42
43
    /**
44
     * @param string $apiKey
45
     * @return $this
46
     */
47
    public function setApiKey(string $apiKey): self
48
    {
49
        Credentials::setApiKey($apiKey);
50
        return $this;
51
    }
52
53
    /**
54
     * @param string $secret
55
     * @return $this
56
     */
57
    public function setSecret(string $secret): self
58
    {
59
        Credentials::setSecret($secret);
60
        return $this;
61
    }
62
63
    /**
64
     * @param string $host
65
     * @param string $endpointClassName
66
     * @param IParametersInterface|null $parameters
67
     * @return IResponseInterface
68
     * @throws SDKException
69
     */
70
    public function publicEndpoint(string $endpointClassName, ?IParametersInterface $parameters = null): IEndpointInterface
71
    {
72
        if (empty(Credentials::getHost())) {
73
            throw new SDKException("Host must be specified");
74
        }
75
76
        return $this->endpoint($endpointClassName, $parameters);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->endpoint($...ClassName, $parameters) returns the type Carpenstar\ByBitAPI\Core...aces\IEndpointInterface which is incompatible with the documented return type Carpenstar\ByBitAPI\Core...aces\IResponseInterface.
Loading history...
77
    }
78
79
    /**
80
     * @param string $endpointClassName
81
     * @param IParametersInterface|null $parameters
82
     * @return IResponseInterface
83
     * @throws SDKException
84
     */
85
    public function privateEndpoint(string $endpointClassName, ?IParametersInterface $parameters = null): IEndpointInterface
86
    {
87
        if (empty(Credentials::getHost())) {
88
            throw new SDKException("Host must be specified");
89
        }
90
        if (empty(Credentials::getApiKey())) {
91
            throw new SDKException("Api key must be specified");
92
        }
93
        if (empty(Credentials::getSecret())) {
94
            throw new SDKException("Client secret must be specified");
95
        }
96
97
        return $this->endpoint($endpointClassName, $parameters);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->endpoint($...ClassName, $parameters) returns the type Carpenstar\ByBitAPI\Core...aces\IEndpointInterface which is incompatible with the documented return type Carpenstar\ByBitAPI\Core...aces\IResponseInterface.
Loading history...
98
    }
99
100
    /**
101
     *
102
     * @param string $endpointClassName
103
     * @param AbstractParameters $params
104
     * @return IEndpointInterface
105
     * @throws \Exception
106
     */
107
    private function endpoint(string $endpointClassName, AbstractParameters $parameters = null): IEndpointInterface
108
    {
109
        return RestBuilder::make($endpointClassName, $parameters);
110
    }
111
112
    /**
113
     * Soon at v.5.1.0.0
114
     * @param string $webSocketChannelClassName
115
     * @param array $data
116
     * @return void
117
     * @throws \Exception
118
     */
119
    private function websocket(string $webSocketChannelClassName, IWebSocketArgumentInterface $data, IChannelHandlerInterface $channelHandler, int $mode = EnumOutputMode::MODE_ENTITY, int $wsClientTimeout = IWebSocketArgumentInterface::DEFAULT_SOCKET_CLIENT_TIMEOUT): void
0 ignored issues
show
Unused Code introduced by
The method websocket() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
120
    {
121
        WebSocketsBuilder::make($webSocketChannelClassName, $data, $channelHandler, $mode, $wsClientTimeout)->execute();
122
    }
123
}
124
125