PublicTradingRecordsResponseItem   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 133
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
dl 0
loc 133
rs 10
c 1
b 0
f 0
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A setIsBuyerMaker() 0 4 1
A setPrice() 0 4 1
A getPrice() 0 3 1
A getIsBuyerMaker() 0 3 1
A setTime() 0 4 1
A setType() 0 4 1
A setQty() 0 4 1
A getTime() 0 3 1
A getType() 0 3 1
A getQuantity() 0 3 1
1
<?php
2
3
namespace Carpenstar\ByBitAPI\Spot\MarketData\PublicTradingRecords\Response;
4
5
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper;
6
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse;
7
use Carpenstar\ByBitAPI\Spot\MarketData\PublicTradingRecords\Interfaces\IPublicTradingRecordsResponseItemInterface;
8
9
class PublicTradingRecordsResponseItem extends AbstractResponse implements IPublicTradingRecordsResponseItemInterface
10
{
11
    /**
12
     * Order price
13
     * @var null|float $price
14
     */
15
    private ?float $price;
16
17
    /**
18
     * Current timestamp
19
     * @var \DateTime $time
20
     */
21
    private \DateTime $time;
22
23
    /**
24
     * Order quantity
25
     * @var float $quantity
26
     */
27
    private float $qty;
28
29
    /**
30
     * 0:Sell or taker order, 1:Buy maker order
31
     * @var bool $isBuyerMaker
32
     */
33
    private bool $isBuyerMaker;
34
35
    /**
36
     * 0:normal trade, 1:Paradigm block trade
37
     * @var int $type
38
     */
39
    private int $type;
40
41
    /**
42
     * @param array $data
43
     */
44
    public function __construct(array $data)
45
    {
46
        $this
47
            ->setPrice($data['price'])
48
            ->setQty($data['qty'])
49
            ->setTime($data['time'])
50
            ->setIsBuyerMaker((bool)$data['isBuyerMaker'])
51
            ->setType($data['type']);
52
    }
53
54
    /**
55
     * @param string $type
56
     * @return self
57
     */
58
    private function setType(string $type): self
59
    {
60
        $this->type = $type;
0 ignored issues
show
Documentation Bug introduced by
The property $type was declared of type integer, but $type is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
61
        return $this;
62
    }
63
64
    /**
65
     * @return int
66
     */
67
    public function getType(): int
68
    {
69
        return $this->type;
70
    }
71
72
    /**
73
     * @param float|null $price
74
     * @return PublicTradingRecordsResponseItem
75
     */
76
    private function setPrice(?float $price = null): self
77
    {
78
        $this->price = $price;
79
        return $this;
80
    }
81
82
    /**
83
     * @return float
84
     */
85
    public function getPrice(): float
86
    {
87
        return $this->price;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->price could return the type null which is incompatible with the type-hinted return double. Consider adding an additional type-check to rule them out.
Loading history...
88
    }
89
90
    /**
91
     * @param float $quantity
92
     * @return PublicTradingRecordsResponseItem
93
     */
94
    private function setQty(?float $quantity = null): self
95
    {
96
        $this->qty = $quantity;
97
        return $this;
98
    }
99
100
    /**
101
     * @return float
102
     */
103
    public function getQuantity(): float
104
    {
105
        return $this->qty;
106
    }
107
108
    /**
109
     * @param int $time
110
     * @return PublicTradingRecordsResponseItem
111
     */
112
    private function setTime(int $time): self
113
    {
114
        $this->time = DateTimeHelper::makeFromTimestamp($time);
115
        return $this;
116
    }
117
118
    /**
119
     * @return \DateTime
120
     */
121
    public function getTime(): \DateTime
122
    {
123
        return $this->time;
124
    }
125
126
    /**
127
     * @param bool $isBuyerMaker
128
     * @return PublicTradingRecordsResponseItem
129
     */
130
    private function setIsBuyerMaker(bool $isBuyerMaker): self
131
    {
132
        $this->isBuyerMaker = $isBuyerMaker;
133
        return $this;
134
    }
135
136
    /**
137
     * @return bool
138
     */
139
    public function getIsBuyerMaker(): bool
140
    {
141
        return $this->isBuyerMaker;
142
    }
143
}
144