Passed
Pull Request — master (#8)
by Vladislav
10:51
created

TickersAbstract   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 84
rs 10
c 0
b 0
f 0
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setTopic() 0 4 1
A setData() 0 6 2
A setType() 0 4 1
A setTimestamp() 0 4 1
A getTopic() 0 3 1
A getType() 0 3 1
A getTimestamp() 0 3 1
A __construct() 0 8 1
A getData() 0 3 1
1
<?php
2
namespace Carpenstar\ByBitAPI\WebSockets\Channels\Spot\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 ?ICollectionInterface $data;
29
30
    public function __construct(array $data)
31
    {
32
        $this->data = new EntityCollection();
33
        $this
34
            ->setTopic($data['topic'])
35
            ->setType($data['type'])
36
            ->setData($data['data'])
37
            ->setTimestamp($data['ts']);
38
    }
39
40
    /**
41
     * @param string|null $topic
42
     * @return self
43
     */
44
    private function setTopic(?string $topic): self
45
    {
46
        $this->topic = $topic;
47
        return $this;
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getTopic(): ?string
54
    {
55
        return $this->topic;
56
    }
57
58
    /**
59
     * @param string|null $type
60
     * @return self
61
     */
62
    private function setType(?string $type): self
63
    {
64
        $this->type = $type;
65
        return $this;
66
    }
67
    /**
68
     * @return string
69
     */
70
    public function getType(): ?string
71
    {
72
        return $this->type;
73
    }
74
75
    /**
76
     * @param string $timestamp
77
     * @return self
78
     */
79
    private function setTimestamp(string $timestamp): self
80
    {
81
        $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

81
        $this->timestamp = DateTimeHelper::makeFromTimestamp(/** @scrutinizer ignore-type */ $timestamp);
Loading history...
82
        return $this;
83
    }
84
85
    /**
86
     * @return \DateTime
87
     */
88
    public function getTimestamp(): \DateTime
89
    {
90
        return $this->timestamp;
91
    }
92
93
    private function setData(array $data): self
94
    {
95
        if (!empty($data)) {
96
            $this->data->push(ResponseBuilder::make(TickersItemAbstract::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

96
            $this->data->/** @scrutinizer ignore-call */ 
97
                         push(ResponseBuilder::make(TickersItemAbstract::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

96
            $this->data->/** @scrutinizer ignore-call */ 
97
                         push(ResponseBuilder::make(TickersItemAbstract::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...
97
        }
98
        return $this;
99
    }
100
101
    public function getData(): ICollectionInterface
102
    {
103
        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...
104
    }
105
}