Passed
Pull Request — master (#10)
by Vladislav
15:29 queued 07:37
created

BooktickerResponse::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 18
rs 9.9332
1
<?php
2
3
namespace Carpenstar\ByBitAPI\WebSockets\Channels\Spot\PublicChannels\Bookticker\Entities;
4
5
use Carpenstar\ByBitAPI\Core\Helpers\DateTimeHelper;
6
use Carpenstar\ByBitAPI\Core\Objects\AbstractResponse;
7
use Carpenstar\ByBitAPI\Core\Builders\ResponseDtoBuilder;
8
use Carpenstar\ByBitAPI\Core\Objects\Collection\EntityCollection;
9
use Carpenstar\ByBitAPI\WebSockets\Channels\Spot\PublicChannels\OrderBook\Entities\OrderBookPriceAbstract;
0 ignored issues
show
Bug introduced by
The type Carpenstar\ByBitAPI\WebS...\OrderBookPriceAbstract 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...
10
11
class BooktickerResponse extends AbstractResponse
12
{
13
    /**
14
     * Topic name
15
     * @var string
16
     */
17
    private string $topic;
18
19
    /**
20
     * The timestamp (ms) that message is sent out
21
     * @var \DateTime $requestTimestamp
22
     */
23
    private \DateTime $requestTimestamp;
24
25
    /**
26
     * Data type. snapshot
27
     * @var string $type
28
     */
29
    private string $type;
30
31
    private EntityCollection $data;
32
33
34
    public function __construct(array $data)
35
    {
36
        $collection = new EntityCollection();
37
38
        $this->topic = $data['topic'];
39
        $this->requestTimestamp = DateTimeHelper::makeFromTimestamp($data['ts']);
40
        $this->type = $data['type'];
41
42
        if (!empty($data['data'])) {
43
            
44
            $data['data'] = array_is_list($data['data']) ? $data['data'] : [$data['data']];
0 ignored issues
show
Bug introduced by
The function array_is_list was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

44
            $data['data'] = /** @scrutinizer ignore-call */ array_is_list($data['data']) ? $data['data'] : [$data['data']];
Loading history...
45
46
            array_map(function ($item) use ($collection) {
47
                $collection->push(ResponseDtoBuilder::make(BoocktickerResponseItem::class, $item));
48
            }, $data['data']);
49
        }
50
51
        $this->data = $collection;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getTopic(): string
58
    {
59
        return $this->topic;
60
    }
61
62
    /**
63
     * @return \DateTime
64
     */
65
    public function getRequestTimestamp(): \DateTime
66
    {
67
        return $this->requestTimestamp;
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getType(): string
74
    {
75
        return $this->type;
76
    }
77
78
    public function getData(): array
79
    {
80
        return $this->data->all();
81
    }
82
}
83