KlineArgument::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 3
dl 0
loc 9
rs 10
1
<?php
2
3
namespace Carpenstar\ByBitAPI\WebSockets\Spot\PublicChannels\Kline\Argument;
4
5
use Carpenstar\ByBitAPI\Core\Enums\WebSocketSpotIntervalEnum;
6
use Carpenstar\ByBitAPI\Core\Enums\WebSocketTopicNameEnum;
7
use Carpenstar\ByBitAPI\Core\Objects\WebSockets\WebSocketArgument;
8
9
class KlineArgument extends WebSocketArgument
10
{
11
    private string $interval;
12
13
    public function __construct(string $symbol, string $interval, ?string $reqId = null)
14
    {
15
        parent::__construct($symbol, $reqId);
16
17
        if (!in_array($interval, WebSocketSpotIntervalEnum::ALL)) {
18
            throw new \Exception("Invalid interval {$interval} specified. See the list of available intervals in the file: " . WebSocketSpotIntervalEnum::class);
19
        }
20
21
        $this->interval = $interval;
22
    }
23
24
    /**
25
     * @return array
26
     */
27
    public function getTopic(): array
28
    {
29
        $topics = [];
30
        foreach (explode(',', $this->symbols) as $symbol) {
31
            $topics[] = WebSocketTopicNameEnum::SPOT_KLINE . ".{$this->interval}.{$symbol}";
32
        }
33
34
        return $topics;
35
    }
36
}
37