SubscribeBooks::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Codenixsv\BitfinexWs\Request;
6
7
use Ratchet\RFC6455\Messaging\Frame;
8
9
/**
10
 * Class SubscribeBooks
11
 * @package Codenixsv\BitfinexWs\Request
12
 */
13
class SubscribeBooks implements Request
14
{
15
    /** @var string */
16
    private $symbol;
17
18
    /** @var string */
19
    private $precision;
20
21
    /** @var string */
22
    private $frequency;
23
24
    /** @var string */
25
    private $length;
26
27
    /**
28
     * SubscribeBooks constructor.
29
     * @param string $symbol
30
     * @param string $precision
31
     * @param string $frequency
32
     * @param string $length
33
     */
34 3
    public function __construct(string $symbol, string $precision, string $frequency, string $length)
35
    {
36 3
        $this->symbol = $symbol;
37 3
        $this->precision = $precision;
38 3
        $this->frequency = $frequency;
39 3
        $this->length = $length;
40 3
    }
41
42
    /**
43
     * @return array
44
     */
45 3
    public function getPayload(): array
46
    {
47
        return [
48 3
            'event' => 'subscribe',
49 3
            'channel' => 'book',
50 3
            'symbol' => $this->symbol,
51 3
            'prec' => $this->precision,
52 3
            'freq' => $this->frequency,
53 3
            'len' => $this->length,
54
55
        ];
56
    }
57
58
    /**
59
     * @return Frame
60
     */
61 2
    public function getFrame(): Frame
62
    {
63 2
        return new Frame(json_encode($this->getPayload()));
64
    }
65
}
66