Completed
Push — master ( 13633f...2513f1 )
by Joachim
15:06
created

Price   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 270
Duplicated Lines 7.41 %

Importance

Changes 0
Metric Value
wmc 23
dl 20
loc 270
c 0
b 0
f 0
rs 10

21 Methods

Rating   Name   Duplication   Size   Complexity  
A getSpecialOfferPrice() 0 3 1
A setSpecialOfferPrice() 9 9 2
A getAvance() 0 3 1
A setIsoCode() 0 4 1
A setAvance() 0 4 1
A getB2bGroupId() 0 3 1
A __construct() 0 3 1
A setCurrencyCode() 0 4 1
A setB2bGroupId() 0 4 1
A getId() 0 3 1
A getCurrencyCode() 0 3 1
A setAmount() 0 4 1
A setId() 0 4 1
A setPeriod() 0 4 1
A getAmount() 0 3 1
A getPeriod() 0 3 1
A getProducts() 0 3 1
A setUnitPrice() 9 9 2
A getUnitPrice() 0 3 1
A getIsoCode() 0 3 1
A setProducts() 0 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 Loevgaard\DandomainFoundation\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Loevgaard\DandomainFoundation;
8
use Loevgaard\DandomainFoundation\Entity\Generated\PriceInterface;
9
use Loevgaard\DandomainFoundation\Entity\Generated\PriceTrait;
10
use Money\Money;
11
12
/**
13
 * @ORM\Entity()
14
 * @ORM\Table(name="loevgaard_dandomain_prices")
15
 */
16
class Price implements PriceInterface
17
{
18
    use PriceTrait;
19
20
    /**
21
     * @var int
22
     *
23
     * @ORM\Id
24
     * @ORM\GeneratedValue
25
     * @ORM\Column(type="integer")
26
     **/
27
    protected $id;
28
29
    /**
30
     * @var int|null
31
     *
32
     * @ORM\Column(nullable=true, type="integer")
33
     */
34
    protected $amount;
35
36
    /**
37
     * @var int|null
38
     *
39
     * @ORM\Column(nullable=true, type="integer")
40
     */
41
    protected $avance;
42
43
    /**
44
     * @var string|null
45
     *
46
     * @ORM\Column(nullable=true, type="string", length=191)
47
     */
48
    protected $b2bGroupId;
49
50
    /**
51
     * @var string|null
52
     *
53
     * @ORM\Column(nullable=true, type="string", length=3)
54
     */
55
    protected $currencyCode;
56
57
    /**
58
     * @var int|null
59
     *
60
     * @ORM\Column(nullable=true, type="integer")
61
     */
62
    protected $isoCode;
63
64
    /**
65
     * @var int|null
66
     *
67
     * @ORM\Column(nullable=true, type="integer")
68
     */
69
    protected $specialOfferPrice;
70
71
    /**
72
     * @var int|null
73
     *
74
     * @ORM\Column(nullable=true, type="integer")
75
     */
76
    protected $unitPrice;
77
78
    /**
79
     * @var Period|null
80
     *
81
     * @ORM\JoinColumn(onDelete="SET NULL")
82
     * @ORM\ManyToOne(targetEntity="Period")
83
     */
84
    protected $period;
85
86
    /**
87
     * @var Product[]|ArrayCollection
88
     *
89
     * @ORM\ManyToMany(mappedBy="prices", targetEntity="Product")
90
     */
91
    protected $products;
92
93
    public function __construct()
94
    {
95
        $this->products = new ArrayCollection();
96
    }
97
98
    /**
99
     * @return int
100
     */
101
    public function getId(): int
102
    {
103
        return (int)$this->id;
104
    }
105
106
    /**
107
     * @param int $id
108
     * @return Price
109
     */
110
    public function setId(int $id)
111
    {
112
        $this->id = $id;
113
        return $this;
114
    }
115
116
    /**
117
     * @return int|null
118
     */
119
    public function getAmount()
120
    {
121
        return $this->amount;
122
    }
123
124
    /**
125
     * @param int|null $amount
126
     * @return Price
127
     */
128
    public function setAmount($amount)
129
    {
130
        $this->amount = $amount;
131
        return $this;
132
    }
133
134
    /**
135
     * @return int|null
136
     */
137
    public function getAvance()
138
    {
139
        return $this->avance;
140
    }
141
142
    /**
143
     * @param int|null $avance
144
     * @return Price
145
     */
146
    public function setAvance($avance)
147
    {
148
        $this->avance = $avance;
149
        return $this;
150
    }
151
152
    /**
153
     * @return null|string
154
     */
155
    public function getB2bGroupId()
156
    {
157
        return $this->b2bGroupId;
158
    }
159
160
    /**
161
     * @param null|string $b2bGroupId
162
     * @return Price
163
     */
164
    public function setB2bGroupId($b2bGroupId)
165
    {
166
        $this->b2bGroupId = $b2bGroupId;
167
        return $this;
168
    }
169
170
    /**
171
     * @return null|string
172
     */
173
    public function getCurrencyCode()
174
    {
175
        return $this->currencyCode;
176
    }
177
178
    /**
179
     * @param null|string $currencyCode
180
     * @return Price
181
     */
182
    public function setCurrencyCode($currencyCode)
183
    {
184
        $this->currencyCode = $currencyCode;
185
        return $this;
186
    }
187
188
    /**
189
     * @return int|null
190
     */
191
    public function getIsoCode()
192
    {
193
        return $this->isoCode;
194
    }
195
196
    /**
197
     * @param int|null $isoCode
198
     * @return Price
199
     */
200
    public function setIsoCode($isoCode)
201
    {
202
        $this->isoCode = $isoCode;
203
        return $this;
204
    }
205
206
    /**
207
     * @return Money|null
208
     */
209
    public function getSpecialOfferPrice()
210
    {
211
        return DandomainFoundation\createMoney((string)$this->currencyCode, (int)$this->specialOfferPrice);
212
    }
213
214
    /**
215
     * @param Money|null $specialOfferPrice
216
     * @return Price
217
     */
218 View Code Duplication
    public function setSpecialOfferPrice(Money $specialOfferPrice = null)
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...
219
    {
220
        if($specialOfferPrice) {
221
            $this->specialOfferPrice = $specialOfferPrice->getAmount();
0 ignored issues
show
Documentation Bug introduced by
It seems like $specialOfferPrice->getAmount() of type string is incompatible with the declared type null|integer of property $specialOfferPrice.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
222
            $this->setCurrencyCode($specialOfferPrice->getCurrency()->getCode());
223
        } else {
224
            $this->specialOfferPrice = $specialOfferPrice;
225
        }
226
        return $this;
227
    }
228
229
    /**
230
     * @return Money|null
231
     */
232
    public function getUnitPrice()
233
    {
234
        return DandomainFoundation\createMoney((string)$this->currencyCode, (int)$this->unitPrice);
235
    }
236
237
    /**
238
     * @param Money|null $unitPrice
239
     * @return Price
240
     */
241 View Code Duplication
    public function setUnitPrice(Money $unitPrice = null)
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...
242
    {
243
        if($unitPrice) {
244
            $this->unitPrice = $unitPrice->getAmount();
0 ignored issues
show
Documentation Bug introduced by
It seems like $unitPrice->getAmount() of type string is incompatible with the declared type null|integer of property $unitPrice.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
245
            $this->setCurrencyCode($unitPrice->getCurrency()->getCode());
246
        } else {
247
            $this->unitPrice = $unitPrice;
248
        }
249
        return $this;
250
    }
251
252
    /**
253
     * @return Period|null
254
     */
255
    public function getPeriod()
256
    {
257
        return $this->period;
258
    }
259
260
    /**
261
     * @param Period|null $period
262
     * @return Price
263
     */
264
    public function setPeriod($period)
265
    {
266
        $this->period = $period;
267
        return $this;
268
    }
269
270
    /**
271
     * @return ArrayCollection|Product[]
272
     */
273
    public function getProducts()
274
    {
275
        return $this->products;
276
    }
277
278
    /**
279
     * @param ArrayCollection|Product[] $products
280
     * @return Price
281
     */
282
    public function setProducts($products)
283
    {
284
        $this->products = $products;
285
        return $this;
286
    }
287
}
288