Completed
Push — master ( b59c0c...c68fa7 )
by Josef
08:24
created

Cart   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 51
ccs 17
cts 17
cp 1
rs 10
c 2
b 1
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addItem() 0 4 1
A getItems() 0 4 1
A getCurrentPrice() 0 7 1
A countTotalAmount() 0 10 2
1
<?php declare(strict_types = 1);
2
3
namespace SlevomatCsobGateway;
4
5
class Cart
6
{
7
8
	/**
9
	 * @var CartItem[]
10
	 */
11
	private $items = [];
12
13
	/**
14
	 * @var Currency
15
	 */
16
	private $currency;
17
18 2
	public function __construct(Currency $currency)
19
	{
20 2
		$this->currency = $currency;
21 2
	}
22
23 2
	public function addItem(string $name, int $quantity, int $amount, string $description = null)
24
	{
25 2
		$this->items[] = new CartItem($name, $quantity, $amount, $description);
26 2
	}
27
28
	/**
29
	 * @return CartItem[]
30
	 */
31 1
	public function getItems(): array
32
	{
33 1
		return $this->items;
34
	}
35
36 1
	public function getCurrentPrice(): Price
37
	{
38 1
		return new Price(
39 1
			$this->countTotalAmount(),
40 1
			$this->currency
41
		);
42
	}
43
44 1
	private function countTotalAmount(): int
45
	{
46 1
		$totalAmount = 0;
47
48 1
		foreach ($this->items as $item) {
49 1
			$totalAmount += $item->getAmount();
50
		}
51
52 1
		return $totalAmount;
53
	}
54
55
}
56