Passed
Pull Request — master (#25)
by Chris
03:05
created

Fixed::getDiscount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace OpenTickets\Tickets\Domain\ValueObject\DiscountType;
4
5
use OpenTickets\Tickets\Domain\Service\Configuration;
6
use OpenTickets\Tickets\Domain\ValueObject\Basket;
7
use OpenTickets\Tickets\Domain\ValueObject\Money;
8
use OpenTickets\Tickets\Domain\ValueObject\Price;
9
use JMS\Serializer\Annotation as Jms;
10
11
class Fixed 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
        return $this->discount;
31
    }
32
33
    /**
34
     * @return Price
35
     */
36
    public function getDiscount(): Price
37
    {
38
        return $this->discount;
39
    }
40
41 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...
42
    {
43
        if (isset($data['net'])) {
44
            $amount = new Money($data['net'], $configuration->getCurrency());
45
            $discount = Price::fromNetCost($amount, $configuration->getTaxRate());
46
        } else {
47
            $amount = new Money($data['gross'], $configuration->getCurrency());
48
            $discount = Price::fromGrossCost($amount, $configuration->getTaxRate());
49
        }
50
51
        return new static($discount);
52
    }
53
}
54