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