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

PublicTradeAbstract   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 230
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 47
dl 0
loc 230
rs 10
c 0
b 0
f 0
wmc 19

19 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A setRequestTimestamp() 0 4 1
A setType() 0 4 1
A setIsTaker() 0 4 1
A getQuantity() 0 3 1
A getType() 0 3 1
A getTradingTime() 0 3 1
A setQuantity() 0 4 1
A setTopic() 0 4 1
A getTradeId() 0 3 1
A getIsTaker() 0 3 1
A setTradeId() 0 4 1
A getRequestTimestamp() 0 3 1
A getPrice() 0 3 1
A setTradingTime() 0 4 1
A getTopic() 0 3 1
A setPrice() 0 4 1
A getTradeType() 0 3 1
A setTradeType() 0 4 1
1
<?php
2
namespace Carpenstar\ByBitAPI\WebSockets\Channels\Spot\PublicChannels\PublicTrade\Entities;
3
4
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper;
5
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse;
6
7
class PublicTradeAbstract extends AbstractResponse
8
{
9
    /**
10
     * Topic name
11
     * @var string $topic
12
     */
13
    private string $topic;
14
15
    /**
16
     * The timestamp (ms) that message is sent out
17
     * @var \DateTime $requestTimestamp
18
     */
19
    private \DateTime $requestTimestamp;
20
21
    /**
22
     * Data type. snapshot
23
     * @var string $type
24
     */
25
    private string $type;
26
27
    /**
28
     * Trade ID
29
     * @var string $tradeId
30
     */
31
    private string $tradeId;
32
33
    /**
34
     * Timestamp (trading time in the match box)
35
     * @var \DateTime $tradingTime
36
     */
37
    private \DateTime $tradingTime;
38
39
    /**
40
     * Price
41
     * @var float $price
42
     */
43
    private float $price;
44
45
    /**
46
     * Quantity
47
     * @var float $quantity
48
     */
49
    private float $quantity;
50
51
    /**
52
     * True indicates buy side is taker, false indicates sell side is taker
53
     * @var bool $isTaker
54
     */
55
    private bool $isTaker;
56
57
    /**
58
     * Trade type. 0:Spot trade. 1:Paradigm block trade
59
     * @var int $tradeType
60
     */
61
    private int $tradeType;
62
63
    public function __construct(array $data)
64
    {
65
        $this
66
            ->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...adeAbstract::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

66
            ->setTopic(/** @scrutinizer ignore-type */ $data['topic'] ?? null)
Loading history...
67
            ->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 $requestTimestamp 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

67
            ->setRequestTimestamp(/** @scrutinizer ignore-type */ $data['ts'] ?? null)
Loading history...
68
            ->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...radeAbstract::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

68
            ->setType(/** @scrutinizer ignore-type */ $data['type'] ?? null)
Loading history...
69
            ->setTradeId($data['data']['v'] ?? null)
0 ignored issues
show
Bug introduced by
It seems like $data['data']['v'] ?? null can also be of type null; however, parameter $tradeId of Carpenstar\ByBitAPI\WebS...eAbstract::setTradeId() 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

69
            ->setTradeId(/** @scrutinizer ignore-type */ $data['data']['v'] ?? null)
Loading history...
70
            ->setTradingTime($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 $tradingTime of Carpenstar\ByBitAPI\WebS...tract::setTradingTime() 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

70
            ->setTradingTime(/** @scrutinizer ignore-type */ $data['data']['t'] ?? null)
Loading history...
71
            ->setPrice($data['data']['p'] ?? null)
0 ignored issues
show
Bug introduced by
It seems like $data['data']['p'] ?? null can also be of type null; however, parameter $price of Carpenstar\ByBitAPI\WebS...adeAbstract::setPrice() does only seem to accept double, 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

71
            ->setPrice(/** @scrutinizer ignore-type */ $data['data']['p'] ?? null)
Loading history...
72
            ->setQuantity($data['data']['q'] ?? null)
0 ignored issues
show
Bug introduced by
It seems like $data['data']['q'] ?? null can also be of type null; however, parameter $quantity of Carpenstar\ByBitAPI\WebS...Abstract::setQuantity() does only seem to accept double, 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

72
            ->setQuantity(/** @scrutinizer ignore-type */ $data['data']['q'] ?? null)
Loading history...
73
            ->setTradeType($data['data']['m'] ?? null)
0 ignored issues
show
Bug introduced by
It seems like $data['data']['m'] ?? null can also be of type null; however, parameter $tradeType of Carpenstar\ByBitAPI\WebS...bstract::setTradeType() does only seem to accept integer, 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

73
            ->setTradeType(/** @scrutinizer ignore-type */ $data['data']['m'] ?? null)
Loading history...
74
            ->setIsTaker($data['data']['type'] ?? null);
0 ignored issues
show
Bug introduced by
It seems like $data['data']['type'] ?? null can also be of type null; however, parameter $isTaker of Carpenstar\ByBitAPI\WebS...eAbstract::setIsTaker() does only seem to accept boolean, 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

74
            ->setIsTaker(/** @scrutinizer ignore-type */ $data['data']['type'] ?? null);
Loading history...
75
    }
76
77
    /**
78
     * @param string $topic
79
     * @return PublicTradeAbstract
80
     */
81
    private function setTopic(string $topic): self
82
    {
83
        $this->topic = $topic;
84
        return $this;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getTopic(): string
91
    {
92
        return $this->topic;
93
    }
94
95
    /**
96
     * @param string $type
97
     * @return PublicTradeAbstract
98
     */
99
    private function setType(string $type): self
100
    {
101
        $this->type = $type;
102
        return $this;
103
    }
104
105
    /**
106
     * @return string
107
     */
108
    public function getType(): string
109
    {
110
        return $this->type;
111
    }
112
113
    /**
114
     * @param float $price
115
     * @return PublicTradeAbstract
116
     */
117
    private function setPrice(float $price): self
118
    {
119
        $this->price = $price;
120
        return $this;
121
    }
122
123
    /**
124
     * @return float
125
     */
126
    public function getPrice(): float
127
    {
128
        return $this->price;
129
    }
130
131
    /**
132
     * @param float $quantity
133
     * @return PublicTradeAbstract
134
     */
135
    private function setQuantity(float $quantity): self
136
    {
137
        $this->quantity = $quantity;
138
        return $this;
139
    }
140
141
    /**
142
     * @return float
143
     */
144
    public function getQuantity(): float
145
    {
146
        return $this->quantity;
147
    }
148
149
    /**
150
     * @param string $tradeId
151
     * @return PublicTradeAbstract
152
     */
153
    private function setTradeId(string $tradeId): self
154
    {
155
        $this->tradeId = $tradeId;
156
        return $this;
157
    }
158
159
    /**
160
     * @return string
161
     */
162
    public function getTradeId(): string
163
    {
164
        return $this->tradeId;
165
    }
166
167
    /**
168
     * @param int $tradeType
169
     * @return PublicTradeAbstract
170
     */
171
    private function setTradeType(int $tradeType): self
172
    {
173
        $this->tradeType = $tradeType;
174
        return $this;
175
    }
176
177
    /**
178
     * @return int
179
     */
180
    public function getTradeType(): int
181
    {
182
        return $this->tradeType;
183
    }
184
185
    /**
186
     * @param string $tradingTime
187
     * @return PublicTradeAbstract
188
     */
189
    private function setTradingTime(string $tradingTime): self
190
    {
191
        $this->tradingTime = DateTimeHelper::makeFromTimestamp($tradingTime);
0 ignored issues
show
Bug introduced by
$tradingTime 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

191
        $this->tradingTime = DateTimeHelper::makeFromTimestamp(/** @scrutinizer ignore-type */ $tradingTime);
Loading history...
192
        return $this;
193
    }
194
195
    /**
196
     * @return \DateTime
197
     */
198
    public function getTradingTime(): \DateTime
199
    {
200
        return $this->tradingTime;
201
    }
202
203
    /**
204
     * @param string $requestTimestamp
205
     * @return PublicTradeAbstract
206
     */
207
    private function setRequestTimestamp(string $requestTimestamp): self
208
    {
209
        $this->requestTimestamp = DateTimeHelper::makeFromTimestamp($requestTimestamp);
0 ignored issues
show
Bug introduced by
$requestTimestamp 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

209
        $this->requestTimestamp = DateTimeHelper::makeFromTimestamp(/** @scrutinizer ignore-type */ $requestTimestamp);
Loading history...
210
        return $this;
211
    }
212
213
    /**
214
     * @return \DateTime
215
     */
216
    public function getRequestTimestamp(): \DateTime
217
    {
218
        return $this->requestTimestamp;
219
    }
220
221
    /**
222
     * @param bool $isTaker
223
     * @return PublicTradeAbstract
224
     */
225
    private function setIsTaker(bool $isTaker): self
226
    {
227
        $this->isTaker = $isTaker;
228
        return $this;
229
    }
230
231
    /**
232
     * @return bool
233
     */
234
    public function getIsTaker(): bool
235
    {
236
        return $this->isTaker;
237
    }
238
}