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

Cart::getItems()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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