KlineArgument   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 26
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A getTopic() 0 8 2
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