CentralAzerbaijanBank   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 58.14 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 25
loc 43
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 8 8 2
A import() 17 23 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
9
namespace Newscoop\PaywallBundle\Importer;
10
11
/**
12
 * Central Azerbaijan Bank Importer class.
13
 */
14
class CentralAzerbaijanBank extends AbstractImporter
15
{
16
    private $url = 'http://www.cbar.az/currencies/';
17
18
    /**
19
     * {@inheritdoc}
20
     */
21 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...
22
    {
23
        if (!isset($options['base_currency'])) {
24
            throw new \InvalidArgumentException('"base_currency" must be set in order to use CentralAzerbaijanBank.');
25
        }
26
27
        $this->baseCurrency = $options['base_currency'];
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function import(array $managedCurrencies = array())
34
    {
35
        $now = new \DateTime('now');
36
        $this->url = $this->url.$now->format('d.m.Y').'.xml';
37
        $xml = simplexml_load_file($this->url);
38 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...
39
            // base currency: AZN
40
            $this->updateOrCreate($managedCurrencies, $this->baseCurrency, 1.00);
41
42
            $data = $xml->xpath('//ValCurs/*[1]');
43
            // divides 1.00 by current exchange rate to get the reverse rate,
44
            // because CBAR provides only inverse rate
45
            foreach ($data[0]->children() as $child) {
46
                $this->updateOrCreate(
47
                    $managedCurrencies,
48
                    (string) $child->attributes()->Code,
49
                    1.00 / (float) $child->children()->Value
50
                );
51
            }
52
53
            $this->manager->flush();
54
        }
55
    }
56
}
57