Passed
Push — master ( 1b5ca4...e52b3a )
by Vladislav
17:19 queued 15:01
created

TickersResponse   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

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

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 3 1
A setTimestamp() 0 4 1
A setCrossSequence() 0 4 1
A setData() 0 4 1
A getTopic() 0 3 1
A getTimestamp() 0 3 1
A __construct() 0 9 1
A setType() 0 4 1
A setTopic() 0 4 1
A getData() 0 3 1
A getCrossSequence() 0 3 1
1
<?php
2
3
namespace Carpenstar\ByBitAPI\WebSockets\Channels\Derivatives\PublicChannels\Tickers\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\Interfaces\ICollectionInterface;
9
use Carpenstar\ByBitAPI\Core\Objects\Collection\EntityCollection;
10
use Carpenstar\ByBitAPI\WebSockets\Channels\Derivatives\PublicChannels\Tickers\Entities\TickersResponseItem;
11
12
/**
13
 * https://bybit-exchange.github.io/docs/derivatives/ws-public/ticker
14
 * Get latest information of the symbol
15
 * Future has snapshot and delta types. If a key does not exist in the field, it means the value is not changed.
16
 * Option has snapshot data only.
17
 *
18
 * Topic: tickers.{symbol}
19
 *
20
 * Push frequency: 100ms
21
 */
22
class TickersResponse extends AbstractResponse
23
{
24
    private ?string $topic;
25
26
    private ?string $type;
27
28
    private \DateTime $timestamp;
29
30
    private int $crossSequence;
31
32
    private ?ICollectionInterface $data;
33
34
    public function __construct(array $data)
35
    {
36
        $this->data = new EntityCollection();
37
        $this
38
            ->setTopic($data['topic'])
39
            ->setType($data['type'])
40
            ->setData($data['data'])
41
            ->setTimestamp($data['ts'])
42
            ->setCrossSequence($data['cs']);
43
    }
44
45
    /**
46
     * @param string|null $topic
47
     * @return self
48
     */
49
    private function setTopic(?string $topic): self
50
    {
51
        $this->topic = $topic;
52
        return $this;
53
    }
54
55
    /**
56
     * @return string
57
     */
58
    public function getTopic(): ?string
59
    {
60
        return $this->topic;
61
    }
62
63
    /**
64
     * @param string|null $type
65
     * @return self
66
     */
67
    private function setType(?string $type): self
68
    {
69
        $this->type = $type;
70
        return $this;
71
    }
72
    /**
73
     * @return string
74
     */
75
    public function getType(): ?string
76
    {
77
        return $this->type;
78
    }
79
80
    /**
81
     * @param string $timestamp
82
     * @return self
83
     */
84
    private function setTimestamp(string $timestamp): self
85
    {
86
        $this->timestamp = DateTimeHelper::makeFromTimestamp($timestamp);
0 ignored issues
show
Bug introduced by
$timestamp 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

86
        $this->timestamp = DateTimeHelper::makeFromTimestamp(/** @scrutinizer ignore-type */ $timestamp);
Loading history...
87
        return $this;
88
    }
89
90
    /**
91
     * @return \DateTime
92
     */
93
    public function getTimestamp(): \DateTime
94
    {
95
        return $this->timestamp;
96
    }
97
98
    /**
99
     * @param int $crossSequence
100
     * @return self
101
     */
102
    private function setCrossSequence(int $crossSequence): self
103
    {
104
        $this->crossSequence = $crossSequence;
105
        return $this;
106
    }
107
108
    /**
109
     * @return int
110
     */
111
    public function getCrossSequence(): int
112
    {
113
        return $this->crossSequence;
114
    }
115
116
    private function setData(array $data): self
117
    {
118
        $this->data->push(ResponseDtoBuilder::make(TickersResponseItem::class, $data));
0 ignored issues
show
Unused Code introduced by
The call to Carpenstar\ByBitAPI\Core...ectionInterface::push() has too many arguments starting with Carpenstar\ByBitAPI\Core...onseItem::class, $data). ( Ignorable by Annotation )

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

118
        $this->data->/** @scrutinizer ignore-call */ 
119
                     push(ResponseDtoBuilder::make(TickersResponseItem::class, $data));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
Bug introduced by
The method push() does not exist on null. ( Ignorable by Annotation )

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

118
        $this->data->/** @scrutinizer ignore-call */ 
119
                     push(ResponseDtoBuilder::make(TickersResponseItem::class, $data));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
119
        return $this;
120
    }
121
122
    public function getData(): array
123
    {
124
        return $this->data->all();
125
    }
126
}
127