OrderBook::mapResponse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace CryptoMarkets\Binance\Endpoints;
4
5
class OrderBook extends Endpoint
6
{
7
    /**
8
     * Get the request url.
9
     *
10
     * @return string
11
     */
12
    public function getUrl()
13
    {
14
        return parent::getUrl().'v1/depth';
15
    }
16
17
    /**
18
     * Get the request method.
19
     *
20
     * @return string
21
     */
22
    public function getMethod()
23
    {
24
        return 'GET';
25
    }
26
27
    /**
28
     * Get the request data.
29
     *
30
     * @return array
31
     */
32 View Code Duplication
    public function getData()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
    {
34
        return [
35
            'symbol' => $this->params['symbol'],
36
            'limit'  => $this->params['limit'] ?? null,
37
        ];
38
    }
39
40
    /**
41
     * Map the given array to create a response object.
42
     *
43
     * @param  array  $data
44
     * @return array
45
     */
46
    public function mapResponse(array $data = [])
47
    {
48
        return [
49
            'bids' => $this->transform($data['bids']),
50
            'asks' => $this->transform($data['asks']),
51
        ];
52
    }
53
54
    /**
55
     * Transform the given orders.
56
     *
57
     * @param  array  $orders
58
     * @return array
59
     */
60
    protected function transform(array $orders)
61
    {
62
        return array_map(function ($order) {
63
            return [
64
                'price' => $order[0],
65
                'amount' => $order[1],
66
                'timestamp' => null,
67
            ];
68
        }, $orders);
69
    }
70
}
71