AmountDiscount   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 40
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setValue() 0 4 1
A removeDiscount() 0 3 1
A __construct() 0 3 1
A addDiscount() 0 3 1
A getValue() 0 3 1
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