1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelCryptoStats\Connectors; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use GuzzleHttp\Client; |
7
|
|
|
use LaravelCryptoStats\Services\CurrencyManager; |
8
|
|
|
|
9
|
|
|
abstract class AbstractConnector |
10
|
|
|
{ |
11
|
|
|
use CurrencyManager; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Array of the cryptocurrencies supported |
15
|
|
|
* by the each of the API connector. |
16
|
|
|
* |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
public $supported_currencies; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Prefix for the API urls. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $api_url_prefix; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Link to the API description. |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $api_description; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Prefix with the url of the corresponding block explorer |
37
|
|
|
* for creating block link. |
38
|
|
|
* |
39
|
|
|
* @var type |
|
|
|
|
40
|
|
|
*/ |
41
|
|
|
protected $block_link_prefix; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* LaravelCryptoStats buider. |
45
|
|
|
* |
46
|
|
|
* Setting the $currency variable for accessing in the child classes |
47
|
|
|
*/ |
48
|
|
|
public function __construct() |
49
|
|
|
{ |
50
|
|
|
$this->config = config('laravel_crypto_stats'); |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Set the currency for the connector. |
55
|
|
|
* |
56
|
|
|
* @param string $currency |
57
|
|
|
* |
58
|
|
|
* @throws Exception |
59
|
|
|
*/ |
60
|
|
|
public function setCurrency(string $currency) |
61
|
|
|
{ |
62
|
|
|
if ($currency) { |
63
|
|
|
$this->currency = $currency; |
64
|
|
|
} else { |
65
|
|
|
throw new Exception('Currency can not be empty!'); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Validating if the input cryptocurrency address is a suitable address |
71
|
|
|
* for the $currency variable value. |
72
|
|
|
* |
73
|
|
|
* @param bool $address |
74
|
|
|
* |
75
|
|
|
* @return bool |
76
|
|
|
*/ |
77
|
|
|
abstract public function validateAddress(string $address): bool; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get balance of the cryptocurrency wallet address. |
81
|
|
|
* |
82
|
|
|
* @param string $address |
83
|
|
|
* |
84
|
|
|
* @return float |
85
|
|
|
*/ |
86
|
|
|
abstract public function getBalance(string $address): float; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Get the wallet link to the corresponding block explorer (block link). |
90
|
|
|
* |
91
|
|
|
* @param string $address |
92
|
|
|
* |
93
|
|
|
* @return string |
94
|
|
|
*/ |
95
|
|
|
abstract public function getBlockExplorerLink(string $address): string; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Process the API response. |
99
|
|
|
* |
100
|
|
|
* @param string $url |
101
|
|
|
* |
102
|
|
|
* @return mixed |
103
|
|
|
*/ |
104
|
|
|
abstract protected function apiCall(string $url); |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Wrappep of the Guzzle client for univarsal sending API calls |
108
|
|
|
* to all of the suitable cryptocurrency connectors. |
109
|
|
|
* |
110
|
|
|
* @param string $url |
111
|
|
|
* |
112
|
|
|
* @return mixed |
113
|
|
|
*/ |
114
|
|
|
protected function sendApiRequest(string $url) |
115
|
|
|
{ |
116
|
|
|
if ($url) { |
117
|
|
|
$client = new Client(); |
118
|
|
|
$response = $client->request('GET', $url); |
119
|
|
|
|
120
|
|
|
if ($response) { |
121
|
|
|
$response_body = json_decode($response->getBody(), true); |
122
|
|
|
|
123
|
|
|
return $response_body; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
throw new Exception('Something wrong with API '.$url.' call!'); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Round the balance value which was getted from the getBalance(). |
132
|
|
|
* |
133
|
|
|
* @param type $balance |
134
|
|
|
* |
135
|
|
|
* @throws Exception |
136
|
|
|
* |
137
|
|
|
* @return float |
138
|
|
|
*/ |
139
|
|
|
protected function roundBalance($balance): float |
140
|
|
|
{ |
141
|
|
|
if (isset($balance)) { |
142
|
|
|
return round($balance, 8); |
|
|
|
|
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
throw new Exception('Balance can not be empty!'); |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths