BasePrice::fromUdb3ModelTariff()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace CultuurNet\UDB3\PriceInfo;
4
5
use Broadway\Serializer\SerializableInterface;
6
use CultuurNet\UDB3\Model\ValueObject\Price\Tariff as Udb3ModelTariff;
7
use ValueObjects\Money\Currency;
8
use ValueObjects\Money\CurrencyCode;
9
10
class BasePrice implements SerializableInterface
11
{
12
    /**
13
     * @var Price
14
     */
15
    private $price;
16
17
    /**
18
     * @var string
19
     */
20
    private $currencyCodeString;
21
22
    /**
23
     * @param Price $price
24
     * @param Currency $currency
25
     */
26
    public function __construct(
27
        Price $price,
28
        Currency $currency
29
    ) {
30
        $this->price = $price;
31
        $this->currencyCodeString = $currency->getCode()->toNative();
32
    }
33
34
    /**
35
     * @return Price
36
     */
37
    public function getPrice()
38
    {
39
        return $this->price;
40
    }
41
42
    /**
43
     * @return Currency
44
     */
45
    public function getCurrency()
46
    {
47
        return Currency::fromNative($this->currencyCodeString);
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    public function serialize()
54
    {
55
        return [
56
            'price' => $this->price->toNative(),
57
            'currency' => $this->currencyCodeString,
58
        ];
59
    }
60
61
    /**
62
     * @param array $data
63
     * @return BasePrice
64
     */
65
    public static function deserialize(array $data)
66
    {
67
        return new BasePrice(
68
            new Price($data['price']),
69
            Currency::fromNative($data['currency'])
70
        );
71
    }
72
73
    /**
74
     * @param Udb3ModelTariff $tariff
75
     * @return BasePrice
76
     */
77 View Code Duplication
    public static function fromUdb3ModelTariff(Udb3ModelTariff $tariff)
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...
78
    {
79
        return new BasePrice(
80
            new Price($tariff->getPrice()->getAmount()),
81
            new Currency(CurrencyCode::fromNative($tariff->getPrice()->getCurrency()->getName()))
82
        );
83
    }
84
}
85