Passed
Push — master ( 8e7304...5050b5 )
by Vladislav
05:53 queued 14s
created

TickersAbstract::getTopic()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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

84
        $this->timestamp = DateTimeHelper::makeFromTimestamp(/** @scrutinizer ignore-type */ $timestamp);
Loading history...
85
        return $this;
86
    }
87
88
    /**
89
     * @return \DateTime
90
     */
91
    public function getTimestamp(): \DateTime
92
    {
93
        return $this->timestamp;
94
    }
95
96
    /**
97
     * @param int $crossSequence
98
     * @return self
99
     */
100
    private function setCrossSequence(int $crossSequence): self
101
    {
102
        $this->crossSequence = $crossSequence;
103
        return $this;
104
    }
105
106
    /**
107
     * @return int
108
     */
109
    public function getCrossSequence(): int
110
    {
111
        return $this->crossSequence;
112
    }
113
114
    private function setData(array $data): self
115
    {
116
        if (!empty($data)) {
117
            $this->data->push(ResponseBuilder::make(TickersDataItemAbstract::class, $data));
0 ignored issues
show
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

117
            $this->data->/** @scrutinizer ignore-call */ 
118
                         push(ResponseBuilder::make(TickersDataItemAbstract::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...
Unused Code introduced by
The call to Carpenstar\ByBitAPI\Core...ectionInterface::push() has too many arguments starting with Carpenstar\ByBitAPI\Core...Abstract::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

117
            $this->data->/** @scrutinizer ignore-call */ 
118
                         push(ResponseBuilder::make(TickersDataItemAbstract::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...
118
        }
119
        return $this;
120
    }
121
122
    public function getData(): ICollectionInterface
123
    {
124
        return $this->data;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->data could return the type null which is incompatible with the type-hinted return Carpenstar\ByBitAPI\Core...es\ICollectionInterface. Consider adding an additional type-check to rule them out.
Loading history...
125
    }
126
}