Generic   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A quote() 0 4 1
A bindCurrencies() 0 7 2
A __construct() 0 5 1
1
<?php
2
3
4
namespace ElePHPant\Quotation;
5
6
7
use ElePHPant\Quotation\Quotation;
8
use ElePHPant\Quotation\QuotationTraits\QuotationTraits;
9
10
/**
11
 * Class Generic
12
 * User: Sérgio Danilo Jr ( @sergiodanilojr )
13
 * Date: 15/06/2020
14
 * Time: 18:52
15
 */
16
class Generic
17
{
18
    use QuotationTraits;
19
20
    /**
21
     * Generic constructor.
22
     * @param array $currencies
23
     * @param string $formatResponse
24
     */
25
    public function __construct(array $currencies, $formatResponse = Quotation::RESPONSE_JSON)
26
    {
27
        $this->currency = $this->bindCurrencies($currencies);
28
        $this->format = $this->setFormat($formatResponse);
29
        $this->base = "https://economia.awesomeapi.com.br/{$this->format}/";
30
    }
31
32
    /**
33
     * @return mixed|null
34
     */
35
    public function quote()
36
    {
37
        $this->endpoint = "all/{$this->currency}";
38
        return $this->connect();
39
    }
40
41
    /**
42
     * @param array $currencies
43
     * @return string
44
     */
45
    private function bindCurrencies(array $currencies): string
46
    {
47
        if (count($currencies) < 2) {
48
            throw new \Error("This method need a array bigger that 1. Provide one more Currency");
49
        }
50
51
        return implode(",", $currencies);
52
    }
53
}