Cryptocurrency::getDescription()   A
last analyzed

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
/**
4
 * Cryptocurrency list package.
5
 * All cryptocurrencies infos in a single package without using a database.
6
 *
7
 * Copyright (C) 2018-2019 <Crypto Technology srl>
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation, either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 */
22
23
declare(strict_types=1);
24
25
namespace CryptoTech\Cryptocurrency;
26
27
use CryptoTech\Cryptocurrency\Exception\CryptoNotEnabledException;
28
use CryptoTech\Cryptocurrency\Exception\CryptoNotFoundException;
29
30
class Cryptocurrency implements CryptocurrencyInterface
31
{
32
    /**
33
     * Cryptocurrency CoinMarketCap id.
34
     *
35
     * @var int
36
     */
37
    protected $id = 0;
38
39
    /**
40
     * Cryptocurrency name.
41
     *
42
     * @var string
43
     */
44
    protected $name = '';
45
46
    /**
47
     * Cryptocurrency symbol.
48
     *
49
     * @var string
50
     */
51
    protected $symbol = '';
52
53
    /**
54
     * Cryptocurrency type.
55
     *
56
     * @var string
57
     */
58
    protected $type = '';
59
60
    /**
61
     * Cryptocurrency logo.
62
     *
63
     * @var string
64
     */
65
    protected $logo = '';
66
67
    /**
68
     * Cryptocurrency mineable.
69
     *
70
     * @var bool
71
     */
72
    protected $mineable = false;
73
74
    /**
75
     * Cryptocurrency description.
76
     *
77
     * @var string
78
     */
79
    protected $description = '';
80
81
    /**
82
     * Cryptocurrency website url.
83
     *
84
     * @var array
85
     */
86
    protected $website = [];
87
88
    /**
89
     * Cryptocurrency explorer urls.
90
     *
91
     * @var array
92
     */
93
    protected $explorer = [];
94
95
    /**
96
     * Cryptocurrency sourcecode url.
97
     *
98
     * @var array
99
     */
100
    protected $source_code = [];
101
102
    /**
103
     * {@inheritdoc}
104
     */
105
    public function getId(): int
106
    {
107
        return $this->id;
108
    }
109
110
    /**
111
     * {@inheritdoc}
112
     */
113
    public function getName(): string
114
    {
115
        return $this->name;
116
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121
    public function getSymbol(): string
122
    {
123
        return $this->symbol;
124
    }
125
126
    /**
127
     * {@inheritdoc}
128
     */
129
    public function getType(): string
130
    {
131
        return $this->type;
132
    }
133
134
    /**
135
     * {@inheritdoc}
136
     */
137
    public function getLogo($size, $path): string
138
    {
139
        return $path.'crypto-logo'.DIRECTORY_SEPARATOR.(string) $size.'px'.DIRECTORY_SEPARATOR.$this->id.'.png';
140
    }
141
142
    /**
143
     * {@inheritdoc}
144
     */
145
    public function isMineable(): bool
146
    {
147
        return $this->mineable;
148
    }
149
150
    /**
151
     * {@inheritdoc}
152
     */
153
    public function setDescription($description)
154
    {
155
        $this->description = $description;
156
    }
157
158
    /**
159
     * {@inheritdoc}
160
     */
161
    public function getDescription(): string
162
    {
163
        return $this->description;
164
    }
165
166
    /**
167
     * {@inheritdoc}
168
     */
169
    public function setProjectUrl($website)
170
    {
171
        $this->website = $website;
172
    }
173
174
    /**
175
     * {@inheritdoc}
176
     */
177
    public function getProjectUrl(): array
178
    {
179
        return $this->website;
180
    }
181
182
    /**
183
     * {@inheritdoc}
184
     */
185
    public function setExplorerUrl($explorer)
186
    {
187
        $this->explorer = $explorer;
188
    }
189
190
    /**
191
     * {@inheritdoc}
192
     */
193
    public function getExplorerUrl(): array
194
    {
195
        return $this->explorer;
196
    }
197
198
    /**
199
     * {@inheritdoc}
200
     */
201
    public function setSourceCodeUrl($source_code)
202
    {
203
        $this->source_code = $source_code;
204
    }
205
206
    /**
207
     * {@inheritdoc}
208
     */
209
    public function getSourceCodeUrl(): array
210
    {
211
        return $this->source_code;
212
    }
213
214
    /**
215
     * {@inheritdoc}
216
     */
217
    public function build()
218
    {
219
    }
220
221
    /**
222
     * Cryptocurrency loader.
223
     *
224
     * @param string $name
225
     * Must be the class name of the selected cryptocurrency.
226
     *
227
     * @throws \CryptoTech\Cryptocurrency\Exception\CryptoNotFoundException
228
     * @throws \CryptoTech\Cryptocurrency\Exception\CryptoNotEnabledException
229
     *
230
     * @return \CryptoTech\Cryptocurrency\Cryptocurrency
231
     */
232
    public function load(string $name): Cryptocurrency
233
    {
234
        $class_name = '\\CryptoTech\\Cryptocurrency\\'.$name;
235
        if ( ! in_array($name, CryptocurrencyCollection::$crypto_enabled, false)) {
236
            if ( ! class_exists($class_name)) {
237
                /* @noinspection PhpUnhandledExceptionInspection */
238
                throw new CryptoNotFoundException(sprintf('Cryptocurrency class "%s" not found! This cryptocurrency is not implemented yet.', $class_name));
239
            }
240
241
            /* @noinspection PhpUnhandledExceptionInspection */
242
            throw new CryptoNotEnabledException(sprintf('The cryptocurrency ("%s") you have selected is not enabled in your configuration!', $name));
243
        }
244
245
        return call_user_func([new $class_name($name), 'build']);
246
    }
247
}
248