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

FixedTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 54
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
dl 54
loc 54
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A provideTestApply() 19 19 1
A __construct() 13 13 1
A testApply() 4 4 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\DiscountType;
4
5
use ConferenceTools\Tickets\Domain\Service\Configuration;
6
use ConferenceTools\Tickets\Domain\ValueObject\Basket;
7
use ConferenceTools\Tickets\Domain\ValueObject\Money;
8
use ConferenceTools\Tickets\Domain\ValueObject\Price;
9
use ConferenceTools\Tickets\Domain\ValueObject\TicketReservation;
10
11 View Code Duplication
class FixedTest 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...
12
{
13
    /**
14
     * @var Configuration
15
     */
16
    private $config;
17
18
    public function __construct($name = null, array $data = array(), $dataName = '')
19
    {
20
        parent::__construct($name, $data, $dataName);
21
        $this->config = Configuration::fromArray([
22
            'tickets' => [
23
                'early' => ['name' => 'Early Bird', 'cost' => 5000, 'available' => 75],
24
                'std' => ['name' => 'Standard', 'cost' => 10000, 'available' => 150],
25
                'free' => ['name' => 'Free', 'cost' => 0, 'available' => 0]
26
            ],
27
            'financial' => [
28
                'taxRate' => 10,
29
                'currency' => 'GBP',
30
                'displayTax' => true
31
            ]
32
        ]);
33
    }
34
35
    /**
36
     * @dataProvider provideTestApply
37
     * @param $basket
38
     * @param Price $expected
39
     */
40
    public function testApply(Basket $basket, Price $discount, Price $expected)
41
    {
42
        $sut = new Fixed($discount);
43
        $this->assertTrue($expected->equals($sut->apply($basket)), 'Price didn\'t match expected value');
44
    }
45
46
    public function provideTestApply()
47
    {
48
        return [
49
            [
50
                Basket::fromReservations(
51
                    $this->config,
52
                    new TicketReservation($this->config->getTicketType('std'), 'abc'),
53
                    new TicketReservation($this->config->getTicketType('std'), 'abc')
54
                ),
55
                Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate()),
56
                Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate())
57
            ],
58
            [
59
                Basket::fromReservations(
60
                    $this->config,
61
                    new TicketReservation($this->config->getTicketType('std'), 'abc')
62
                ),
63
                Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate()),
64
                Price::fromNetCost(new Money(1000, $this->config->getCurrency()), $this->config->getTaxRate())
65
            ]
66
        ];
67
    }
68
}