GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CurrencyService   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 93
ccs 19
cts 19
cp 1
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A currencyToSymbol() 0 6 2
A getCurrencyConverter() 0 3 1
A getCurrencyWebservice() 0 3 1
A symbolToCurrency() 0 7 2
A getCurrencies() 0 3 1
1
<?php
2
3
namespace Awin\ReportTask\Bundle\ReportBundle\Service;
4
5
use Awin\ReportTask\Bundle\ReportBundle\Exception\CurrencyNotFoundException;
6
use Awin\ReportTask\Bundle\ReportBundle\Model\CurrencyConverter;
7
use Awin\ReportTask\Bundle\ReportBundle\Model\CurrencyWebservice;
8
9
/**
10
 * The currencies aggregation services on currency conversion process
11
 *
12
 * @date       24/06/2017
13
 * @time       18:49
14
 * @author     Peng Yue <[email protected]>
15
 * @copyright  2004-2017 Peng Yue
16
 */
17
18
class CurrencyService implements CurrencyServiceInterface
19
{
20
    /**
21
     * The available currencies
22
     *
23
     * @var array
24
     */
25
    private $currencies = [
26
        'GBP' => '£',
27
        'EUR' => '€',
28
        'USD' => '$'
29
    ];
30
31
    /**
32
     * @var CurrencyConverter
33
     */
34
    private $currencyConverter;
35
36
    /**
37
     * @var CurrencyWebservice
38
     */
39
    private $currencyWebservice;
40
41
    /**
42
     * CurrencyService constructor.
43
     */
44 12
    public function __construct()
45
    {
46 12
        $this->currencyWebservice   = new CurrencyWebservice();
47 12
        $this->currencyConverter    = new CurrencyConverter($this->currencyWebservice, $this->currencies);
48 12
    }
49
50
    /**
51
     * Get the instance of the currency converter
52
     *
53
     * @return CurrencyConverter
54
     */
55 2
    public function getCurrencyConverter()
56
    {
57 2
        return $this->currencyConverter;
58
    }
59
60
    /**
61
     * Get the instance of the currency webservice
62
     *
63
     * @return CurrencyWebservice
64
     */
65 1
    public function getCurrencyWebservice()
66
    {
67 1
        return $this->currencyWebservice;
68
    }
69
70
    /**
71
     * Get the available currencies list
72
     *
73
     * @return array
74
     */
75 2
    public function getCurrencies()
76
    {
77 2
        return $this->currencies;
78
    }
79
80
    /**
81
     * Get the currency symbol with currency ISO code
82
     *
83
     * @param string $currency
84
     *
85
     * @throw  \Awin\ReportTask\Bundle\ReportBundle\Exception\CurrencyNotFoundException
86
     * @return string
87
     */
88 4
    public function currencyToSymbol($currency)
89
    {
90 4
        if (!array_key_exists($currency, $this->currencies)) {
91 1
            throw new CurrencyNotFoundException($currency);
92
        }
93 3
        return $this->currencies[$currency];
94
    }
95
96
    /**
97
     * Get the currency ISO code with currency symbol
98
     *
99
     * @param string $symbol
100
     *
101
     * @throw  \Awin\ReportTask\Bundle\ReportBundle\Exception\CurrencyNotFoundException
102
     * @return string
103
     */
104 5
    public function symbolToCurrency($symbol)
105
    {
106 5
        $currencies = array_flip($this->currencies);
107 5
        if (!array_key_exists($symbol, $currencies)) {
108 1
            throw new CurrencyNotFoundException($symbol);
109
        }
110 4
        return $currencies[$symbol];
111
    }
112
}