AmountDiscount::setValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace Sunfox\PriceCalculator\Discount;
4
5
use Nette\SmartObject;
6
use Sunfox\PriceCalculator\IDiscount;
7
8
/**
9
 * @property float $value
10
 */
11 1
final class AmountDiscount implements IDiscount
12
{
13
	use SmartObject;
14
15
	public function __construct(
16
		protected float $value = 0.0
17
	) {
18
	}
19
20
	/**
21
	 * Get discount value.
22
	 */
23
	public function getValue(): float
24
	{
25 1
		return $this->value;
26 1
	}
27
28
	/**
29
	 * Set discount value.
30
	 */
31
	public function setValue(float $value): IDiscount
32
	{
33 1
		$this->value = $value;
34
		return $this;
35
	}
36
37
	/**
38
	 * Returns price after discount.
39 1
	 */
40
	public function addDiscount(float $price): float
41 1
	{
42 1
		return $price - $this->value;
43
	}
44
45
	/**
46
	 * Returns price before discount.
47
	 */
48 1
	public function removeDiscount(float $price): float
49
	{
50 1
		return $price + $this->value;
51
	}
52
}
53