Tariff   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 94
Duplicated Lines 8.51 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 7
dl 8
loc 94
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getName() 0 4 1
A getPrice() 0 4 1
A getCurrency() 0 4 1
A serialize() 0 8 1
A deserialize() 0 8 1
A fromUdb3ModelTariff() 8 8 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 CultuurNet\UDB3\PriceInfo;
4
5
use Broadway\Serializer\SerializableInterface;
6
use CultuurNet\UDB3\Model\ValueObject\Price\Tariff as Udb3ModelTariff;
7
use CultuurNet\UDB3\ValueObject\MultilingualString;
8
use ValueObjects\Money\Currency;
9
use ValueObjects\Money\CurrencyCode;
10
11
class Tariff implements SerializableInterface
12
{
13
    /**
14
     * @var MultilingualString
15
     */
16
    private $name;
17
18
    /**
19
     * @var Price
20
     */
21
    private $price;
22
23
    /**
24
     * @var string
25
     */
26
    private $currencyCodeString;
27
28
    /**
29
     * @param MultilingualString $name
30
     * @param Price $price
31
     * @param Currency $currency
32
     */
33
    public function __construct(
34
        MultilingualString $name,
35
        Price $price,
36
        Currency $currency
37
    ) {
38
        $this->name = $name;
39
        $this->price = $price;
40
        $this->currencyCodeString = $currency->getCode()->toNative();
41
    }
42
43
    /**
44
     * @return MultilingualString
45
     */
46
    public function getName()
47
    {
48
        return $this->name;
49
    }
50
51
    /**
52
     * @return Price
53
     */
54
    public function getPrice()
55
    {
56
        return $this->price;
57
    }
58
59
    /**
60
     * @return Currency
61
     */
62
    public function getCurrency()
63
    {
64
        return Currency::fromNative($this->currencyCodeString);
65
    }
66
67
    /**
68
     * @return array
69
     */
70
    public function serialize()
71
    {
72
        return [
73
            'name' => $this->name->serialize(),
74
            'price' => $this->price->toNative(),
75
            'currency' => $this->currencyCodeString,
76
        ];
77
    }
78
79
    /**
80
     * @param array $data
81
     * @return Tariff
82
     */
83
    public static function deserialize(array $data)
84
    {
85
        return new Tariff(
86
            MultilingualString::deserialize($data['name']),
87
            new Price($data['price']),
88
            Currency::fromNative($data['currency'])
89
        );
90
    }
91
92
    /**
93
     * @param Udb3ModelTariff $udb3ModelTariff
94
     * @return Tariff
95
     */
96 View Code Duplication
    public static function fromUdb3ModelTariff(Udb3ModelTariff $udb3ModelTariff)
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...
97
    {
98
        return new Tariff(
99
            MultilingualString::fromUdb3ModelTranslatedValueObject($udb3ModelTariff->getName()),
100
            new Price($udb3ModelTariff->getPrice()->getAmount()),
101
            new Currency(CurrencyCode::fromNative($udb3ModelTariff->getPrice()->getCurrency()->getName()))
102
        );
103
    }
104
}
105