Cart::getCurrentPrice()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
ccs 4
cts 4
cp 1
crap 1
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway;
4
5
class Cart
6
{
7
8
	/** @var CartItem[] */
9
	private $items = [];
10
11
	/** @var Currency */
12
	private $currency;
13
14 2
	public function __construct(Currency $currency)
15
	{
16 2
		$this->currency = $currency;
17 2
	}
18
19 2
	public function addItem(string $name, int $quantity, int $amount, ?string $description = null): void
20
	{
21 2
		$this->items[] = new CartItem($name, $quantity, $amount, $description);
22 2
	}
23
24
	/**
25
	 * @return CartItem[]
26
	 */
27 1
	public function getItems(): array
28
	{
29 1
		return $this->items;
30
	}
31
32 1
	public function getCurrentPrice(): Price
33
	{
34 1
		return new Price(
35 1
			$this->countTotalAmount(),
36 1
			$this->currency
37
		);
38
	}
39
40 1
	private function countTotalAmount(): int
41
	{
42 1
		$totalAmount = 0;
43
44 1
		foreach ($this->items as $item) {
45 1
			$totalAmount += $item->getAmount();
46
		}
47
48 1
		return $totalAmount;
49
	}
50
51
}
52