Completed
Push — master ( cb4835...b23375 )
by Andrii
03:01
created

MoneyHydratorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 38
loc 38
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 4 4 1
A testHydrateNew() 5 5 1
A testHydrateOld() 6 6 1
A checkValues() 6 6 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
 * API for Billing
4
 *
5
 * @link      https://github.com/hiqdev/billing-hiapi
6
 * @package   billing-hiapi
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\billing\hiapi\tests\unit\vo;
12
13
use Money\Currency;
14
use Money\Money;
15
use Yii;
16
use Zend\Hydrator\HydratorInterface;
17
18
/**
19
 * @author Andrii Vasyliev <[email protected]>
20
 */
21 View Code Duplication
class MoneyHydratorTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Duplication introduced by
This class 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
    const AMOUNT1 = '11111';
24
    const CURRENCY1 = 'USD';
25
26
    const AMOUNT2 = '22222';
27
    const CURRENCY2 = 'EUR';
28
29
    protected $data = [
30
        'amount'    => self::AMOUNT1,
31
        'currency'  => self::CURRENCY1,
32
    ];
33
34
    public function setUp()
35
    {
36
        $this->hydrator = Yii::$container->get(HydratorInterface::class);
37
    }
38
39
    public function testHydrateNew()
40
    {
41
        $obj = $this->hydrator->hydrate($this->data, Money::class);
42
        $this->checkValues($obj);
43
    }
44
45
    public function testHydrateOld()
46
    {
47
        $obj = new Money(self::AMOUNT2, new Currency(self::CURRENCY2));
48
        $obj = $this->hydrator->hydrate($this->data, $obj);
49
        $this->checkValues($obj);
50
    }
51
52
    public function checkValues($obj)
53
    {
54
        $this->assertInstanceOf(Money::class, $obj);
55
        $this->assertSame(self::AMOUNT1, $obj->getAmount());
56
        $this->assertSame(self::CURRENCY1, $obj->getCurrency()->getCode());
57
    }
58
}
59