ConfigurationTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 28.99 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 20
loc 69
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 6 1
A provideValidCurrency() 0 8 1
A testProcessedDefaultCurrency() 8 8 1
A testValidDefaultCurrency() 12 12 1
A provideInvalidCurrency() 0 7 1
A testInvalidDefaultCurrency() 0 10 1

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
namespace Flagbit\Bundle\CurrencyBundle\Tests;
4
5
use Flagbit\Bundle\CurrencyBundle\DependencyInjection\Configuration;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\Config\Definition\Processor;
8
9
class ConfigurationTest extends TestCase
10
{
11
    protected function process($config)
12
    {
13
        $processor = new Processor();
14
15
        return $processor->processConfiguration(new Configuration(), $config);
16
    }
17
18
    public function provideValidCurrency()
19
    {
20
        return [
21
            ['EUR'],
22
            ['USD'],
23
            ['CHF'],
24
        ];
25
    }
26
27
    /**
28
     * Test Default Currency to prevent BC breaks
29
     */
30 View Code Duplication
    public function testProcessedDefaultCurrency()
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...
31
    {
32
        $config = [[]];
33
34
        $config = $this->process($config);
35
36
        $this->assertEquals('EUR', $config['default_currency']);
37
    }
38
39
    /**
40
     * @dataProvider provideValidCurrency
41
     */
42 View Code Duplication
    public function testValidDefaultCurrency($currency)
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...
43
    {
44
        $config = [
45
            [
46
                'default_currency' => $currency,
47
            ]
48
        ];
49
50
        $config = $this->process($config);
51
52
        $this->assertEquals($currency, $config['default_currency']);
53
    }
54
55
    public function provideInvalidCurrency()
56
    {
57
        return [
58
            ['foobar'],
59
            ['eur'],
60
        ];
61
    }
62
63
    /**
64
     * @dataProvider provideInvalidCurrency
65
     * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
66
     */
67
    public function testInvalidDefaultCurrency($currency)
68
    {
69
        $config = [
70
            [
71
                'default_currency' => $currency,
72
            ]
73
        ];
74
75
        $this->process($config);
76
    }
77
}
78