Passed
Pull Request — master (#10)
by Vladislav
15:29 queued 07:37
created

KlineArgument::getInterval()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Carpenstar\ByBitAPI\WebSockets\Channels\Spot\PublicChannels\Kline\Argument;
4
5
use Carpenstar\ByBitAPI\WebSockets\Enums\WebSocketSpotIntervalEnum;
6
use Carpenstar\ByBitAPI\WebSockets\Enums\WebSocketTopicNameEnum;
7
use Carpenstar\ByBitAPI\WebSockets\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