EuropeanCentralBankImporter::configure()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @author Rafał Muszyński <[email protected]>
5
 * @copyright 2015 Sourcefabric z.ú.
6
 * @license http://www.gnu.org/licenses/gpl-3.0.txt
7
 */
8
namespace Newscoop\PaywallBundle\Importer;
9
10
/**
11
 * European Central Bank Importer class.
12
 */
13
class EuropeanCentralBankImporter extends AbstractImporter
14
{
15
    private $url = 'http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml';
16
17
    /**
18
     * {@inheritdoc}
19
     */
20 View Code Duplication
    public function configure(array $options = array())
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22
        if (!isset($options['base_currency'])) {
23
            throw new \InvalidArgumentException('"base_currency" must be set in order to use EuropeanCentralBankImporter.');
24
        }
25
26
        $this->baseCurrency = $options['base_currency'];
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function import(array $managedCurrencies = array())
33
    {
34
        $xml = simplexml_load_file($this->url);
35 View Code Duplication
        if ($xml instanceof \SimpleXMLElement) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
            // base currency: euro
37
            $this->updateOrCreate($managedCurrencies, $this->baseCurrency, 1.00);
38
39
            $data = $xml->xpath('//gesmes:Envelope/*[3]/*');
40
            foreach ($data[0]->children() as $child) {
41
                $this->updateOrCreate($managedCurrencies, (string) $child->attributes()->currency, (float) $child->attributes()->rate);
42
            }
43
44
            $this->manager->flush();
45
        }
46
    }
47
48
    public function setBaseCurrency($baseCurrency = null)
49
    {
50
        $this->baseCurrency = $baseCurrency;
51
    }
52
}
53