LaravelCryptoStats   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __call() 0 13 3
1
<?php
2
3
namespace LaravelCryptoStats;
4
5
use Exception;
6
use LaravelCryptoStats\Services\CurrencyManager;
7
8
class LaravelCryptoStats
9
{
10
    use CurrencyManager;
11
12
    /**
13
     * LaravelCryptoStats buider.
14
     */
15
    public function __construct()
16
    {
17
        $this->config = config('laravel_crypto_stats');
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

17
        $this->config = /** @scrutinizer ignore-call */ config('laravel_crypto_stats');
Loading history...
18
    }
19
20
    /**
21
     * Dynamically call the method of the API connector instance.
22
     *
23
     * @param string $method
24
     * @param array  $parameters
25
     *
26
     * @return mixed
27
     */
28
    public function __call($method, $parameters)
29
    {
30
        if (!$this->currency) {
31
            throw new Exception('Currency can not be null! Call setCurrency() for setting it.');
32
        }
33
        $factory = new LaravelCryptoStatsFactory();
34
        $instance = $factory->getInstance($this->currency);
35
36
        if (!$instance) {
0 ignored issues
show
introduced by
$instance is of type LaravelCryptoStats\connector, thus it always evaluated to true.
Loading history...
37
            throw new Exception('Instance of the LaravelCryptoStats API connector was not created!');
38
        }
39
40
        return $instance->$method(...$parameters);
41
    }
42
}
43