Cart   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 44
rs 10
ccs 17
cts 17
cp 1
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getItems() 0 3 1
A getCurrentPrice() 0 5 1
A addItem() 0 3 1
A countTotalAmount() 0 9 2
A __construct() 0 3 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