FixedPerTicket   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 27.27 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 40%

Importance

Changes 0
Metric Value
dl 12
loc 44
rs 10
c 0
b 0
f 0
ccs 6
cts 15
cp 0.4
wmc 5
lcom 1
cbo 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A apply() 0 5 1
A getDiscount() 0 4 1
A fromArray() 12 12 2

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 JMS\Serializer\Annotation as Jms;
10
11
class FixedPerTicket implements DiscountTypeInterface
12
{
13
    /**
14
     * @JMS\Type("Price")
15
     * @var Price
16
     */
17
    private $discount;
18
19
    /**
20
     * Percentage constructor.
21
     * @param $discount
22
     */
23 2
    public function __construct(Price $discount)
24
    {
25 2
        $this->discount = $discount;
26 2
    }
27
28 2
    public function apply(Basket $to): Price
29
    {
30 2
        $tickets = count($to->getTickets());
31 2
        return $this->discount->multiply($tickets);
32
    }
33
34
    /**
35
     * @return Price
36
     */
37
    public function getDiscount(): Price
38
    {
39
        return $this->discount;
40
    }
41
42 View Code Duplication
    public static function fromArray(array $data, Configuration $configuration): DiscountTypeInterface
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...
43
    {
44
        if (isset($data['net'])) {
45
            $amount = new Money($data['net'], $configuration->getCurrency());
46
            $discount = Price::fromNetCost($amount, $configuration->getTaxRate());
47
        } else {
48
            $amount = new Money($data['gross'], $configuration->getCurrency());
49
            $discount = Price::fromGrossCost($amount, $configuration->getTaxRate());
50
        }
51
52
        return new static($discount);
53
    }
54
}
55