Completed
Push — master ( d02bdd...0a5fc3 )
by Andrii
02:11
created

SinglePriceTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 19.05 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 8 8 1
A tearDown() 0 3 1
A testCalculateUsage() 0 5 1
A testCalculatePrice() 0 5 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
 * PHP Billing Library
4
 *
5
 * @link      https://github.com/hiqdev/php-billing
6
 * @package   php-billing
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\tests\unit\price;
12
13
use hiqdev\php\billing\price\SinglePrice;
14
use hiqdev\php\billing\target\Target;
15
use hiqdev\php\billing\type\Type;
16
use hiqdev\php\units\Quantity;
17
use Money\Money;
18
19
/**
20
 * @author Andrii Vasyliev <[email protected]>
21
 */
22
class SinglePriceTest extends \PHPUnit\Framework\TestCase
23
{
24
    /**
25
     * @var SinglePrice
26
     */
27
    protected $price;
28
29
    /**
30
     * @var SimpleAction
31
     */
32
    protected $action;
33
34
    /**
35
     * @var Money
36
     */
37
    protected $money;
38
39 View Code Duplication
    protected function setUp()
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...
40
    {
41
        $this->target   = new Target('server', 1);
42
        $this->type     = new Type('server_traf');
43
        $this->quantity = Quantity::gigabyte(10);
44
        $this->money    = Money::USD(15);
45
        $this->price    = new SinglePrice(null, $this->type, $this->target, $this->quantity, $this->money);
46
    }
47
48
    protected function tearDown()
49
    {
50
    }
51
52
    public function testCalculateUsage()
53
    {
54
        $this->assertNull($this->price->calculateUsage(Quantity::byte(1)));
55
        $this->assertEquals(Quantity::gigabyte(90), $this->price->calculateUsage(Quantity::gigabyte(100)));
56
    }
57
58
    public function testCalculatePrice()
59
    {
60
        $this->assertEquals($this->money, $this->price->calculatePrice(Quantity::byte(1)));
61
        $this->assertEquals($this->money, $this->price->calculatePrice(Quantity::megabyte(1)));
62
    }
63
}
64