Completed
Push — master ( 7d972a...3baf5c )
by Andrii
02:11
created

GrowingDiscountTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 56.52 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 2
lcom 1
cbo 3
dl 13
loc 23
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildDiscount() 0 6 1
A assertCharges() 13 13 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-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\php\billing\tests\unit\charge\modifiers;
12
13
use DateTimeImmutable;
14
use hiqdev\php\billing\charge\Charge;
15
use hiqdev\php\billing\charge\modifiers\GrowingDiscount;
16
use hiqdev\php\units\Quantity;
17
18
/**
19
 * @author Andrii Vasyliev <[email protected]>
20
 */
21
class GrowingDiscountTest extends FixedDiscountTest
22
{
23
    protected function buildDiscount($value)
24
    {
25
        $month = (new DateTimeImmutable())->modify('first day of this month midnight');
26
27
        return (new GrowingDiscount($value))->since($month)->everyMonth();
28
    }
29
30 View Code Duplication
    public function assertCharges($fd, $sum)
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
        $action = $this->createAction($this->prepaid->multiply(2));
0 ignored issues
show
Bug introduced by
The property prepaid does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
33
        $charge = $action->calculateCharge($this->price);
34
        $charges = $fd->modifyCharge($charge, $action);
35
        $this->assertInternalType('array', $charges);
36
        $this->assertSame(2, count($charges));
37
        $this->assertSame($charge, $charges[0]);
38
        $discount = $charges[1];
39
        $this->assertInstanceOf(Charge::class, $discount);
40
        $this->assertEquals(Quantity::items(1), $discount->getUsage());
41
        $this->assertEquals($sum, $discount->getSum());
42
    }
43
}
44