Completed
Push — master ( 45f7ef...cf154d )
by Simonas
21:47 queued 06:48
created

EcbDriver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 28
wmc 3
lcom 0
cbo 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getRates() 0 13 2
A getBaseCurrency() 0 5 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\CurrencyExchangeBundle\Driver;
13
14
/**
15
 * This class downloads exchange rates from http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml.
16
 */
17
class EcbDriver implements CurrencyDriverInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function getRates()
23
    {
24
        $rates = [];
25
        $xml = @simplexml_load_file('http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml');
26
        $data = $xml->xpath('//gesmes:Envelope/*[3]/*');
27
        foreach ($data[0]->children() as $child) {
28
            $code = (string)$child->attributes()->currency;
29
            $rate = (float)$child->attributes()->rate;
30
            $rates[$code] = $rate;
31
        }
32
33
        return $rates;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getBaseCurrency()
40
    {
41
        // Default base currency of The European Central Bank
42
        return 'EUR';
43
    }
44
}
45