Passed
Push — master ( 8e7304...5050b5 )
by Vladislav
05:53 queued 14s
created

OrderBookAbstract   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 196
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 196
rs 10
c 0
b 0
f 0
wmc 17

15 Methods

Rating   Name   Duplication   Size   Complexity  
A getTopic() 0 3 1
A getAsk() 0 3 1
A getType() 0 3 1
A getSymbol() 0 3 1
A setResponseTimestamp() 0 4 1
A setBid() 0 12 2
A setType() 0 4 1
A getResponseTimestamp() 0 3 1
A setRequestTimestamp() 0 4 1
A setAsk() 0 12 2
A getBid() 0 3 1
A setSymbol() 0 4 1
A __construct() 0 10 1
A getRequestTimestamp() 0 3 1
A setTopic() 0 4 1
1
<?php
2
namespace Carpenstar\ByBitAPI\WebSockets\Channels\Spot\PublicChannels\OrderBook\Entities;
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\AbstractResponse;
9
10
class OrderBookAbstract extends AbstractResponse
11
{
12
    /**
13
     * Topic name
14
     * @var string $topic
15
     */
16
    private string $topic;
17
18
    /**
19
     * Data type. snapshot
20
     * @var string $type
21
     */
22
    private string $type;
23
24
    /**
25
     * Trading pair
26
     * @var string $symbol
27
     */
28
    private string $symbol;
29
30
    /**
31
     * The timestamp that message is sent out
32
     * @var \DateTime $requestTimestamp
33
     */
34
    private \DateTime $requestTimestamp;
35
36
    /**
37
     * The timestamp that system generates the data.
38
     * @var \DateTime $responseTimestamp
39
     */
40
    private \DateTime $responseTimestamp;
41
42
    /**
43
     * @var ICollectionInterface $ask
44
     */
45
    private ICollectionInterface $ask;
46
47
    /**
48
     * @var ICollectionInterface $bid
49
     */
50
    private ICollectionInterface $bid;
51
52
    public function __construct(array $data)
53
    {
54
        $this
55
            ->setSymbol($data['data']['s'] ?? null)
0 ignored issues
show
Bug introduced by
It seems like $data['data']['s'] ?? null can also be of type null; however, parameter $symbol of Carpenstar\ByBitAPI\WebS...okAbstract::setSymbol() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

55
            ->setSymbol(/** @scrutinizer ignore-type */ $data['data']['s'] ?? null)
Loading history...
56
            ->setTopic($data['topic'] ?? null)
0 ignored issues
show
Bug introduced by
It seems like $data['topic'] ?? null can also be of type null; however, parameter $topic of Carpenstar\ByBitAPI\WebS...ookAbstract::setTopic() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

56
            ->setTopic(/** @scrutinizer ignore-type */ $data['topic'] ?? null)
Loading history...
57
            ->setType($data['type'] ?? null)
0 ignored issues
show
Bug introduced by
It seems like $data['type'] ?? null can also be of type null; however, parameter $type of Carpenstar\ByBitAPI\WebS...BookAbstract::setType() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

57
            ->setType(/** @scrutinizer ignore-type */ $data['type'] ?? null)
Loading history...
58
            ->setBid($data['data']['b'] ?? null)
0 ignored issues
show
Bug introduced by
It seems like $data['data']['b'] ?? null can also be of type null; however, parameter $bids of Carpenstar\ByBitAPI\WebS...rBookAbstract::setBid() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

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

58
            ->setBid(/** @scrutinizer ignore-type */ $data['data']['b'] ?? null)
Loading history...
59
            ->setAsk($data['data']['a'] ?? null)
60
            ->setRequestTimestamp($data['ts'] ?? null)
0 ignored issues
show
Bug introduced by
It seems like $data['ts'] ?? null can also be of type null; however, parameter $timestamp of Carpenstar\ByBitAPI\WebS...::setRequestTimestamp() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

60
            ->setRequestTimestamp(/** @scrutinizer ignore-type */ $data['ts'] ?? null)
Loading history...
61
            ->setResponseTimestamp($data['data']['t'] ?? null);
0 ignored issues
show
Bug introduced by
It seems like $data['data']['t'] ?? null can also be of type null; however, parameter $timestamp of Carpenstar\ByBitAPI\WebS...:setResponseTimestamp() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

61
            ->setResponseTimestamp(/** @scrutinizer ignore-type */ $data['data']['t'] ?? null);
Loading history...
62
    }
63
64
    /**
65
     * @param string $topic
66
     * @return self
67
     */
68
    private function setTopic(string $topic): self
69
    {
70
        $this->topic = $topic;
71
        return $this;
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getTopic(): string
78
    {
79
        return $this->topic;
80
    }
81
82
    /**
83
     * @param string $type
84
     * @return self
85
     */
86
    private function setType(string $type): self
87
    {
88
        $this->type = $type;
89
        return $this;
90
    }
91
92
    /**
93
     * @return string
94
     */
95
    public function getType(): string
96
    {
97
        return $this->type;
98
    }
99
100
    /**
101
     * @param string $symbol
102
     * @return self
103
     */
104
    private function setSymbol(string $symbol): self
105
    {
106
        $this->symbol = $symbol;
107
        return $this;
108
    }
109
110
    /**
111
     * @return string
112
     */
113
    public function getSymbol(): string
114
    {
115
        return $this->symbol;
116
    }
117
118
    /**
119
     * @param string $timestamp
120
     * @return self
121
     */
122
    private function setRequestTimestamp(string $timestamp): self
123
    {
124
        $this->requestTimestamp = DateTimeHelper::makeFromTimestamp($timestamp);
0 ignored issues
show
Bug introduced by
$timestamp of type string is incompatible with the type integer expected by parameter $timestamp of Carpenstar\ByBitAPI\Core...er::makeFromTimestamp(). ( Ignorable by Annotation )

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

124
        $this->requestTimestamp = DateTimeHelper::makeFromTimestamp(/** @scrutinizer ignore-type */ $timestamp);
Loading history...
125
        return $this;
126
    }
127
128
    /**
129
     * @return \DateTime
130
     */
131
    public function getRequestTimestamp(): \DateTime
132
    {
133
        return $this->requestTimestamp;
134
    }
135
136
    /**
137
     * @param string $timestamp
138
     * @return self
139
     */
140
    private function setResponseTimestamp(string $timestamp): self
141
    {
142
        $this->responseTimestamp = DateTimeHelper::makeFromTimestamp($timestamp);
0 ignored issues
show
Bug introduced by
$timestamp of type string is incompatible with the type integer expected by parameter $timestamp of Carpenstar\ByBitAPI\Core...er::makeFromTimestamp(). ( Ignorable by Annotation )

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

142
        $this->responseTimestamp = DateTimeHelper::makeFromTimestamp(/** @scrutinizer ignore-type */ $timestamp);
Loading history...
143
        return $this;
144
    }
145
146
    /**
147
     * @return \DateTime
148
     */
149
    public function getResponseTimestamp(): \DateTime
150
    {
151
        return $this->responseTimestamp;
152
    }
153
154
    /**
155
     * @param $asks
156
     * @return self
157
     * @throws \Exception
158
     */
159
    private function setAsk($asks): self
160
    {
161
        $askCollection = new EntityCollection();
162
163
        if (!empty($asks)) {
164
            array_map(function ($askItem) use ($askCollection) {
165
                $askCollection->push(ResponseBuilder::make(OrderBookPriceDTO::class, $askItem));
0 ignored issues
show
Bug introduced by
The type Carpenstar\ByBitAPI\WebS...ities\OrderBookPriceDTO was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
166
            }, $asks);
167
        }
168
169
        $this->ask = $askCollection;
170
        return $this;
171
    }
172
173
    /**
174
     * @return ICollectionInterface
175
     */
176
    public function getAsk(): ICollectionInterface
177
    {
178
        return $this->ask;
179
    }
180
181
    /**
182
     * @param array $bids
183
     * @return OrderBookAbstract
184
     * @throws \Exception
185
     */
186
    private function setBid(array $bids): self
187
    {
188
        $bidCollection = new EntityCollection();
189
190
        if (!empty($bids)) {
191
            array_map(function ($bidItem) use ($bidCollection) {
192
                $bidCollection->push(ResponseBuilder::make(OrderBookPriceDTO::class, $bidItem));
193
            }, $bids);
194
        }
195
196
        $this->bid = $bidCollection;
197
        return $this;
198
    }
199
200
    /**
201
     * @return ICollectionInterface
202
     */
203
    public function getBid(): ICollectionInterface
204
    {
205
        return $this->bid;
206
    }
207
}