CurrencyTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 58.82 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 40
loc 68
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testDefaultCurrency() 0 4 1
A testDefaultCurrencySymbol() 10 10 1
A testCurrencySymbol() 10 10 1
A testDefaultCurrencyName() 10 10 1
A testCurrencyName() 10 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\Service;
4
5
use Flagbit\Bundle\CurrencyBundle\Service\Currency;
6
use PHPUnit\Framework\TestCase;
7
use PHPUnit_Framework_MockObject_MockObject;
8
9
class CurrencyTest extends TestCase
10
{
11
    /**
12
     * @var PHPUnit_Framework_MockObject_MockObject
13
     */
14
    private $currencyBundle;
15
16
    /**
17
     * @var Currency
18
     */
19
    private $currency;
20
21
    protected function setUp()
22
    {
23
        $this->currencyBundle = $this->getMockBuilder('Symfony\Component\Intl\ResourceBundle\CurrencyBundleInterface')
24
            ->getMockForAbstractClass();
25
        $this->currency = new Currency($this->currencyBundle, 'EUR');
0 ignored issues
show
Documentation introduced by
$this->currencyBundle is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...urrencyBundleInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
26
    }
27
28
    public function testDefaultCurrency()
29
    {
30
        $this->assertEquals('EUR', $this->currency->getDefaultCurrency());
31
    }
32
33 View Code Duplication
    public function testDefaultCurrencySymbol()
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...
34
    {
35
        $this->currencyBundle
36
            ->expects($this->once())
37
            ->method('getCurrencySymbol')
38
            ->with('EUR')
39
            ->will($this->returnValue('€'));
40
41
        $this->assertEquals('€', $this->currency->getCurrencySymbol());
42
    }
43
44 View Code Duplication
    public function testCurrencySymbol()
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...
45
    {
46
        $this->currencyBundle
47
            ->expects($this->once())
48
            ->method('getCurrencySymbol')
49
            ->with('USD')
50
            ->will($this->returnValue('$'));
51
52
        $this->assertEquals('$', $this->currency->getCurrencySymbol('USD'));
53
    }
54
55 View Code Duplication
    public function testDefaultCurrencyName()
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...
56
    {
57
        $this->currencyBundle
58
            ->expects($this->once())
59
            ->method('getCurrencyName')
60
            ->with('EUR')
61
            ->will($this->returnValue('Euro'));
62
63
        $this->assertEquals('Euro', $this->currency->getCurrencyName());
64
    }
65
66 View Code Duplication
    public function testCurrencyName()
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...
67
    {
68
        $this->currencyBundle
69
            ->expects($this->once())
70
            ->method('getCurrencyName')
71
            ->with('USD')
72
            ->will($this->returnValue('US Dollar'));
73
74
        $this->assertEquals('US Dollar', $this->currency->getCurrencyName('USD'));
75
    }
76
}
77