OrderBook   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 10.61 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 7
loc 66
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getUrl() 0 4 1
A getMethod() 0 4 1
A mapResponse() 0 7 1
A getData() 7 7 1
A transform() 0 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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