Total Complexity | 7 |
Total Lines | 67 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
10 | class PublicTradeResponse extends AbstractResponse |
||
11 | { |
||
12 | /** |
||
13 | * Topic name |
||
14 | * @var string $topic |
||
15 | */ |
||
16 | private string $topic; |
||
17 | |||
18 | /** |
||
19 | * The timestamp (ms) that message is sent out |
||
20 | * @var \DateTime $requestTime |
||
21 | */ |
||
22 | private \DateTime $requestTime; |
||
23 | |||
24 | /** |
||
25 | * Data type. snapshot |
||
26 | * @var string $type |
||
27 | */ |
||
28 | private string $type; |
||
29 | |||
30 | private EntityCollection $data; |
||
31 | |||
32 | public function __construct(array $data) |
||
33 | { |
||
34 | $this->topic = $data['topic']; |
||
35 | $this->type = $data['type']; |
||
36 | $this->requestTime = DateTimeHelper::makeFromTimestamp($data['ts']); |
||
37 | |||
38 | $collection = new EntityCollection(); |
||
39 | |||
40 | if (!empty($data['data'])) { |
||
41 | $data['data'] = isset($data['data'][0]) ? $data['data'] : [$data['data']]; |
||
42 | array_map(function ($item) use ($collection) { |
||
43 | $collection->push(ResponseDtoBuilder::make(PublicTradeResponseItem::class, $item)); |
||
44 | }, $data['data']); |
||
45 | } |
||
46 | |||
47 | $this->data = $collection; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @return string |
||
52 | */ |
||
53 | public function getTopic(): string |
||
54 | { |
||
55 | return $this->topic; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @return string |
||
60 | */ |
||
61 | public function getType(): string |
||
62 | { |
||
63 | return $this->type; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * @return \DateTime |
||
68 | */ |
||
69 | public function getRequestTime(): \DateTime |
||
72 | } |
||
73 | |||
74 | public function getData(): array |
||
77 | } |
||
78 | } |
||
79 |