Passed
Push — master ( 3e99b0...1fa2df )
by Vladislav
04:12 queued 01:58
created

OrderBookResponse::setAsk()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Carpenstar\ByBitAPI\Derivatives\MarketData\OrderBook\Response;
3
4
use Carpenstar\ByBitAPI\Core\Builders\ResponseBuilder;
5
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper;
6
use Carpenstar\ByBitAPI\Core\Interfaces\ICollectionInterface;
7
use Carpenstar\ByBitAPI\Core\Objects\Collection\EntityCollection;
8
use Carpenstar\ByBitAPI\Core\Objects\ResponseEntity;
9
10
class OrderBookResponse extends ResponseEntity
11
{
12
    private string $symbol;
13
14
    private \DateTime $timestamp;
15
16
    private int $updateId;
17
18
    private ICollectionInterface $bid;
19
20
    private ICollectionInterface $ask;
21
22
    public function __construct(array $data)
23
    {
24
        $this->bid = new EntityCollection();
25
        $this->ask = new EntityCollection();
26
27
        $this
28
            ->setSymbol($data['s'])
29
            ->setTimestamp($data['ts'])
30
            ->setUpdateId($data['u'])
31
            ->setBid($data['b'])
32
            ->setAsk($data['a']);
33
    }
34
35
    /**
36
     * @param string $symbol
37
     * @return self
38
     */
39
    private function setSymbol(string $symbol): self
40
    {
41
        $this->symbol = $symbol;
42
        return $this;
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getSymbol(): string
49
    {
50
        return $this->symbol;
51
    }
52
53
    /**
54
     * @param int $timestamp
55
     * @return self
56
     */
57
    private function setTimestamp(int $timestamp): self
58
    {
59
        $this->timestamp = DateTimeHelper::makeFromTimestamp($timestamp);
60
        return $this;
61
    }
62
63
    /**
64
     * @return \DateTime
65
     */
66
    public function getTimestamp(): \DateTime
67
    {
68
        return $this->timestamp;
69
    }
70
71
    /**
72
     * @param $updateId
73
     * @return self
74
     */
75
    private function setUpdateId($updateId): self
76
    {
77
        $this->updateId = $updateId;
78
        return $this;
79
    }
80
81
    /**
82
     * @return int
83
     */
84
    public function getUpdateId(): int
85
    {
86
        return $this->updateId;
87
    }
88
89
    private function setBid(?array $bids = []): self
90
    {
91
        $bidList = $this->bid;
92
93
        if (!empty($bids)) {
94
            array_map(function ($bid) use ($bidList) {
95
                $bidList->push(ResponseBuilder::make(OrderBookPriceItemResponse::class, $bid));
0 ignored issues
show
Unused Code introduced by
The call to Carpenstar\ByBitAPI\Core...ectionInterface::push() has too many arguments starting with Carpenstar\ByBitAPI\Core...mResponse::class, $bid). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

95
                $bidList->/** @scrutinizer ignore-call */ 
96
                          push(ResponseBuilder::make(OrderBookPriceItemResponse::class, $bid));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
96
            }, $bids);
97
        }
98
99
        return $this;
100
    }
101
102
    /**
103
     * @return ICollectionInterface
104
     */
105
    public function getBid(): ICollectionInterface
106
    {
107
        return $this->bid;
108
    }
109
110
    private function setAsk(?array $asks = []): self
111
    {
112
        $askList = $this->ask;
113
114
        if (!empty($asks)) {
115
            array_map(function ($ask) use ($askList) {
116
                $askList->push(ResponseBuilder::make(OrderBookPriceItemResponse::class, $ask));
0 ignored issues
show
Unused Code introduced by
The call to Carpenstar\ByBitAPI\Core...ectionInterface::push() has too many arguments starting with Carpenstar\ByBitAPI\Core...mResponse::class, $ask). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

116
                $askList->/** @scrutinizer ignore-call */ 
117
                          push(ResponseBuilder::make(OrderBookPriceItemResponse::class, $ask));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
117
            }, $asks);
118
        }
119
120
        return $this;
121
    }
122
123
    /**
124
     * @return ICollectionInterface
125
     */
126
    public function getAsk(): ICollectionInterface
127
    {
128
        return $this->ask;
129
    }
130
}
131
132
/**
133
 * s
134
b	string	Bid. Order by price asc
135
a	string	Ask. Order by price asc
136
137
 */