Coins::getHistory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Codenixsv\CoinGeckoApi\Api;
6
7
use Exception;
8
9
class Coins extends Api
10
{
11
    /**
12
     * @return array
13
     * @throws Exception
14
     */
15 1
    public function getList(): array
16
    {
17 1
        return $this->get('/coins/list');
18
    }
19
20
    /**
21
     * @param string $vsCurrency
22
     * @param array $params
23
     * @return array
24
     * @throws Exception
25
     */
26 1
    public function getMarkets(string $vsCurrency, array $params = []): array
27
    {
28 1
        $params['vs_currency'] = $vsCurrency;
29
30 1
        return $this->get('/coins/markets', $params);
31
    }
32
33
    /**
34
     * @param string $id
35
     * @param array $params
36
     * @return array
37
     * @throws Exception
38
     */
39 1
    public function getCoin(string $id, array $params = []): array
40
    {
41 1
        return $this->get('/coins/' . $id, $params);
42
    }
43
44
    /**
45
     * @param string $id
46
     * @param array $params
47
     * @return array
48
     * @throws Exception
49
     */
50 1
    public function getTickers(string $id, array $params = []): array
51
    {
52 1
        return $this->get('/coins/' . $id . '/tickers', $params);
53
    }
54
55
    /**
56
     * @param string $id
57
     * @param string $date
58
     * @param array $params
59
     * @return array
60
     * @throws Exception
61
     */
62 1
    public function getHistory(string $id, string $date, array $params = []): array
63
    {
64 1
        $params['date'] = $date;
65 1
        return $this->get('/coins/' . $id . '/history', $params);
66
    }
67
68
    /**
69
     * @param string $id
70
     * @param string $vsCurrency
71
     * @param string $days
72
     * @return array
73
     * @throws Exception
74
     */
75 1
    public function getMarketChart(string $id, string $vsCurrency, string $days): array
76
    {
77 1
        $params['vs_currency'] = $vsCurrency;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$params was never initialized. Although not strictly required by PHP, it is generally a good practice to add $params = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
78 1
        $params['days'] = $days;
79 1
        return $this->get('/coins/' . $id . '/market_chart', $params);
80
    }
81
82
    /**
83
     * @param string $id
84
     * @param string $vsCurrency
85
     * @param string $from
86
     * @param string $to
87
     * @return array
88
     * @throws Exception
89
     */
90 1 View Code Duplication
    public function getMarketChartRange(string $id, string $vsCurrency, string $from, string $to): array
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...
91
    {
92 1
        $params['vs_currency'] = $vsCurrency;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$params was never initialized. Although not strictly required by PHP, it is generally a good practice to add $params = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
93 1
        $params['from'] = $from;
94 1
        $params['to'] = $to;
95 1
        return $this->get('/coins/' . $id . '/market_chart/range', $params);
96
    }
97
98
    /**
99
     * @param string $id
100
     * @param array $params
101
     * @return array
102
     * @throws Exception
103
     */
104 1
    public function getStatusUpdates(string $id, array $params = []): array
105
    {
106 1
        return $this->get('/coins/' . $id . '/status_updates', $params);
107
    }
108
}
109