Completed
Push — master ( a84807...ecaeb0 )
by Martin
13:02
created

Cryptocurrency::getFunction()   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
3
declare(strict_types=1);
4
5
namespace cHeeSaW\AlphaVantageBundle\Endpoints;
6
7
use InvalidArgumentException;
8
9
/**
10
 * @link https://www.alphavantage.co/documentation/#digital-currency
11
 */
12
class Cryptocurrency implements Endpoint
13
{
14
    public const CRYPTO_CURRENCY_EXCHANGE_RATE = 'CURRENCY_EXCHANGE_RATE';
15
    public const CRYPTO_CURRENCY_DAILY = 'DIGITAL_CURRENCY_DAILY';
16
    public const CRYPTO_CURRENCY_WEEKLY = 'DIGITAL_CURRENCY_WEEKLY';
17
    public const CRYPTO_CURRENCY_MONTHLY = 'DIGITAL_CURRENCY_MONTHLY';
18
19
    private static array $validFunctions = [
20
        self::CRYPTO_CURRENCY_EXCHANGE_RATE,
21
        self::CRYPTO_CURRENCY_DAILY,
22
        self::CRYPTO_CURRENCY_MONTHLY,
23
        self::CRYPTO_CURRENCY_WEEKLY
24
    ];
25
26
    private string $function;
27
28
    /**
29
     * @see https://www.alphavantage.co/physical_currency_list/
30
     * @see https://www.alphavantage.co/digital_currency_list/
31
     */
32
    private ?string $from_currency;
33
34
    /**
35
     * @see https://www.alphavantage.co/physical_currency_list/
36
     * @see https://www.alphavantage.co/digital_currency_list/
37
     */
38
    private ?string $to_currency;
39
40
    /**
41
     * @see https://www.alphavantage.co/digital_currency_list/
42
     */
43
    private ?string $symbol;
44
45
    /**
46
     * The exchange market of your choice. It can be any of the market in the market list.
47
     * For example: market=CNY.
48
     * @see https://www.alphavantage.co/physical_currency_list/
49
     */
50
    private string $market;
51
52
    public function __construct(
53
        string $function,
54
        string $from_currency = null,
55
        string $to_currency = null,
56
        string $symbol = null
57
    ) {
58
        if (!in_array($function, self::$validFunctions, true)) {
59
            throw new InvalidArgumentException(
60
                $function . ' is not valid, check https://www.alphavantage.co/documentation/
61
                for valid Cryptocurrency functions'
62
            );
63
        }
64
65
        $this->function = $function;
66
        $this->from_currency = $from_currency;
67
        $this->to_currency = $to_currency;
68
        $this->symbol = $symbol;
69
    }
70
71
    public static function getValidFunctions(): array
72
    {
73
        return self::$validFunctions;
74
    }
75
76
    public function getFunction(): string
77
    {
78
        return $this->function;
79
    }
80
81
    public function getFromCurrency(): ?string
82
    {
83
        return $this->from_currency;
84
    }
85
86
    public function getToCurrency(): ?string
87
    {
88
        return $this->to_currency;
89
    }
90
91
    public function getSymbol(): ?string
92
    {
93
        return $this->symbol;
94
    }
95
96
    public function getMarket(): string
97
    {
98
        return $this->market;
99
    }
100
101
    public function getQueryString(): string
102
    {
103
        return http_build_query($this);
104
    }
105
}
106