Passed
Push — master ( 6262ca...fbd7eb )
by Vladislav
02:01
created

OrderBookArgument::setDepth()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
namespace Carpenstar\ByBitAPI\WebSockets\Channels\Spot\PublicChannels\OrderBook\Argument;
3
4
use Carpenstar\ByBitAPI\WebSockets\Enums\WebSocketOperationsEnum;
5
use Carpenstar\ByBitAPI\WebSockets\Enums\WebSocketTopicNameEnum;
6
use Carpenstar\ByBitAPI\WebSockets\Objects\WebSockets\WebSocketArgument;
7
8
class OrderBookArgument extends WebSocketArgument
9
{
10
11
    private int $depth;
12
13
    /**
14
     * @return array
15
     * @throws \Exception
16
     */
17
    public function getTopic(): array
18
    {
19
        if (!isset($this->depth)) {
20
            throw new \Exception("You must set depth parameter!");
21
        }
22
23
        $topics = [];
24
        foreach ($this->symbols as $symbol) {
25
            $topics[] = WebSocketTopicNameEnum::ORDERBOOK . ".{$this->getDepth()}." . $symbol;
26
        }
27
28
        return $topics;
29
    }
30
31
    /**
32
     * @param int $depth
33
     * @return $this
34
     */
35
    public function setDepth(int $depth): self
36
    {
37
        $this->depth = $depth;
38
        return $this;
39
    }
40
41
    /**
42
     * @return int
43
     */
44
    public function getDepth(): int
45
    {
46
        return $this->depth;
47
    }
48
49
50
    /**
51
     * @return string
52
     */
53
    public function getOperation(): string
54
    {
55
        return WebSocketOperationsEnum::SUBSCRIBE;
56
    }
57
}