Passed
Pull Request — master (#22)
by Vladislav
08:10
created

BybitAPI::setHost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
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\IResponseInterface;
9
use Carpenstar\ByBitAPI\Core\Interfaces\ISuccessCurlResponseDtoInterface;
10
use Carpenstar\ByBitAPI\Core\Interfaces\IParametersInterface;
11
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...
12
13
class BybitAPI
14
{
15
    /**
16
     * @param string $host
17
     * @return $this
18
     */
19
    public function setHost(string $host): self
20
    {
21
        Credentials::setHost($host);
22
        return $this;
23
    }
24
25
    /**
26
     * @param string $apiKey
27
     * @return $this
28
     */
29
    public function setApiKey(string $apiKey): self
30
    {
31
        Credentials::setApiKey($apiKey);
32
        return $this;
33
    }
34
35
    /**
36
     * @param string $secret
37
     * @return $this
38
     */
39
    public function setSecret(string $secret): self
40
    {
41
        Credentials::setSecret($secret);
42
        return $this;
43
    }
44
45
    /**
46
     * @param string $endpointClassName
47
     * @param IParametersInterface|null $parameters
48
     * @return IResponseInterface
49
     * @throws \Exception
50
     */
51
    public function rest(string $endpointClassName, ?IParametersInterface $parameters = null): IResponseInterface
52
    {
53
        return RestBuilder::make($endpointClassName, $parameters)->execute();
54
    }
55
56
    /**
57
     * @param string $host
58
     * @param string $endpointClassName
59
     * @param IParametersInterface|null $parameters
60
     * @return IResponseInterface
61
     * @throws SDKException
62
     */
63
    public function publicEndpoint(string $endpointClassName, ?IParametersInterface $parameters = null): IResponseInterface
64
    {
65
        if (empty(Credentials::getHost())) {
66
            throw new SDKException("Host must be specified");
67
        }
68
69
        return $this->rest($endpointClassName, $parameters);
70
    }
71
72
    /**
73
     * @param string $host
74
     * @param string $apiKey
75
     * @param string $secret
76
     * @param string $endpointClassName
77
     * @param IParametersInterface|null $parameters
78
     * @return IResponseInterface
79
     * @throws SDKException
80
     */
81
    public function privateEndpoint(string $endpointClassName, ?IParametersInterface $parameters = null): IResponseInterface
82
    {
83
        if (empty(Credentials::getHost())) {
84
            throw new SDKException("Host must be specified");
85
        }
86
        if (empty(Credentials::getApiKey())) {
87
            throw new SDKException("Api key must be specified");
88
        }
89
        if (empty(Credentials::getSecret())) {
90
            throw new SDKException("Client secret must be specified");
91
        }
92
93
        return $this->rest($endpointClassName, $parameters);
94
    }
95
96
    /**
97
     * @param string $webSocketChannelClassName
98
     * @param array $data
99
     * @return void
100
     * @throws \Exception
101
     */
102
    public 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
Bug introduced by
The type Carpenstar\ByBitAPI\IChannelHandlerInterface 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...
Bug introduced by
The type Carpenstar\ByBitAPI\IWebSocketArgumentInterface 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...
103
    {
104
        WebSocketsBuilder::make($webSocketChannelClassName, $data, $channelHandler, $mode, $wsClientTimeout)->execute();
105
    }
106
}
107
108