Passed
Pull Request — master (#69)
by Chris
17:32 queued 08:49
created

PriceTest   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 122
Duplicated Lines 51.64 %

Importance

Changes 0
Metric Value
dl 63
loc 122
rs 10
c 0
b 0
f 0
wmc 13

13 Methods

Rating   Name   Duplication   Size   Complexity  
A provideCompare() 0 11 1
A testSubtract() 6 6 1
A testCompare() 0 4 1
A testLessThan() 8 8 1
A testGreaterThan() 8 8 1
A testIsSameTaxRate() 8 8 1
A testGetTax() 0 4 1
A testFromGrossCost() 6 6 1
A testEquals() 8 8 1
A testFromNetCost() 6 6 1
A testExceptionWithUnequalTaxRates() 0 8 1
A testMultiply() 0 5 1
A testAdd() 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
namespace ConferenceTools\Tickets\Domain\ValueObject;
4
5
class PriceTest extends \PHPUnit\Framework\TestCase
6
{
7 View Code Duplication
    public function testFromNetCost()
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...
8
    {
9
        $sut = Price::fromNetCost(new Money(10, 'GBP'), new TaxRate(20));
10
        self::assertTrue((new Money(12, 'GBP'))->equals($sut->getGross()), 'Gross value incorrect');
11
        self::assertTrue((new Money(10, 'GBP'))->equals($sut->getNet()), 'Net value incorrect');
12
        self::assertTrue((new TaxRate(20))->equals($sut->getTaxRate()), 'Tax rate incorrect');
13
    }
14
15 View Code Duplication
    public function testFromGrossCost()
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...
16
    {
17
        $sut = Price::fromGrossCost(new Money(12, 'GBP'), new TaxRate(20));
18
        self::assertTrue((new Money(12, 'GBP'))->equals($sut->getGross()), 'Gross value incorrect');
19
        self::assertTrue((new Money(10, 'GBP'))->equals($sut->getNet()), 'Net value incorrect');
20
        self::assertTrue((new TaxRate(20))->equals($sut->getTaxRate()), 'Tax rate incorrect');
21
    }
22
23
    /**
24
     * @dataProvider provideCompare
25
     *
26
     * @param Price $a
27
     * @param Price $b
28
     * @param int $expected
29
     */
30
    public function testCompare(Price $a, Price $b, $expected)
31
    {
32
        self::assertEquals($expected, $a->compare($b));
33
        self::assertEquals(-1 * $expected, $b->compare($a));
34
    }
35
36
    public function provideCompare()
37
    {
38
        $a = Price::fromNetCost(new Money(10, 'GBP'), new TaxRate(20));
39
        $b = Price::fromNetCost(new Money(10, 'GBP'), new TaxRate(20));
40
        $c = Price::fromNetCost(new Money(11, 'GBP'), new TaxRate(20));
41
        $d = Price::fromNetCost(new Money(12, 'GBP'), new TaxRate(20));
42
        return [
43
            [$a, $b, 0],
44
            [$b, $c, -1],
45
            [$c, $d, -1],
46
            [$d, $a, 1],
47
        ];
48
    }
49
50 View Code Duplication
    public function testEquals()
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...
51
    {
52
        $sut = Price::fromNetCost(new Money(10, 'GBP'), new TaxRate(20));
53
        $price1 = Price::fromNetCost(new Money(10, 'GBP'), new TaxRate(20));
54
        $price2 = Price::fromNetCost(new Money(11, 'GBP'), new TaxRate(20));
55
56
        self::assertTrue($sut->equals($price1));
57
        self::assertFalse($sut->equals($price2));
58
    }
59
60 View Code Duplication
    public function testLessThan()
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...
61
    {
62
        $sut = Price::fromNetCost(new Money(10, 'GBP'), new TaxRate(20));
63
        $price1 = Price::fromNetCost(new Money(9, 'GBP'), new TaxRate(20));
64
        $price2 = Price::fromNetCost(new Money(11, 'GBP'), new TaxRate(20));
65
66
        self::assertTrue($sut->lessThan($price2));
67
        self::assertFalse($sut->lessThan($price1));
68
    }
69
70 View Code Duplication
    public function testGreaterThan()
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...
71
    {
72
        $sut = Price::fromNetCost(new Money(10, 'GBP'), new TaxRate(20));
73
        $price1 = Price::fromNetCost(new Money(9, 'GBP'), new TaxRate(20));
74
        $price2 = Price::fromNetCost(new Money(11, 'GBP'), new TaxRate(20));
75
76
        self::assertTrue($sut->greaterThan($price1));
77
        self::assertFalse($sut->greaterThan($price2));
78
    }
79
80
    public function testExceptionWithUnequalTaxRates()
81
    {
82
        $this->setExpectedException(\InvalidArgumentException::class);
0 ignored issues
show
Deprecated Code introduced by
The function PHPUnit_Framework_TestCase::setExpectedException() has been deprecated: Method deprecated since Release 5.2.0; use expectException() instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

82
        /** @scrutinizer ignore-deprecated */ $this->setExpectedException(\InvalidArgumentException::class);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
83
84
        $sut = Price::fromNetCost(new Money(10, 'GBP'), new TaxRate(20));
85
        $price1 = Price::fromNetCost(new Money(9, 'GBP'), new TaxRate(10));
86
87
        $sut->compare($price1);
88
    }
89
90 View Code Duplication
    public function testAdd()
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...
91
    {
92
        $price = Price::fromNetCost(new Money(10, 'GBP'), new TaxRate(20));
93
        $sut = (Price::fromNetCost(new Money(10, 'GBP'), new TaxRate(20)))->add($price);
94
95
        self::assertTrue($sut->getNet()->equals(new Money(20, 'GBP')), 'Values did not add up');
96
    }
97
98 View Code Duplication
    public function testSubtract()
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...
99
    {
100
        $price = Price::fromNetCost(new Money(5, 'GBP'), new TaxRate(20));
101
        $sut = (Price::fromNetCost(new Money(10, 'GBP'), new TaxRate(20)))->subtract($price);
102
103
        self::assertTrue($sut->getNet()->equals(new Money(5, 'GBP')), 'Value not subtracted');
104
    }
105
106
    public function testMultiply()
107
    {
108
        $sut = (Price::fromNetCost(new Money(10, 'GBP'), new TaxRate(20)))->multiply(3.5);
109
110
        self::assertTrue($sut->getNet()->equals(new Money(35, 'GBP')), 'Value not multiplied');
111
    }
112
113
    public function testGetTax()
114
    {
115
        $sut = Price::fromNetCost(new Money(10, 'GBP'), new TaxRate(20));
116
        self::assertTrue($sut->getTax()->equals(new Money(2, 'GBP')), 'Tax calculated incorrectly');
117
    }
118
119 View Code Duplication
    public function testIsSameTaxRate()
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...
120
    {
121
        $sut = Price::fromNetCost(new Money(10, 'GBP'), new TaxRate(20));
122
        $price1 = Price::fromNetCost(new Money(10, 'GBP'), new TaxRate(20));
123
        $price2 = Price::fromNetCost(new Money(10, 'GBP'), new TaxRate(10));
124
125
        self::assertTrue($sut->isSameTaxRate($price1));
126
        self::assertFalse($sut->isSameTaxRate($price2));
127
    }
128
}
129