MemoryCartRepository::remove()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Simara\Cart\Infrastructure;
4
5
use Simara\Cart\Domain\Cart\Cart;
6
use Simara\Cart\Domain\Cart\CartNotFoundException;
7
use Simara\Cart\Domain\Cart\CartRepository;
8
9
final class MemoryCartRepository implements CartRepository
10
{
11
    /**
12
     * @var array<string, Cart>
13
     */
14
    private array $carts = [];
15
16 7
    public function add(Cart $cart): void
17
    {
18 7
        $this->carts[$cart->getId()] = $cart;
19 7
    }
20
21 8
    public function get(string $id): Cart
22
    {
23 8
        $this->checkExistence($id);
24 6
        return $this->carts[$id];
25
    }
26
27 9
    private function checkExistence(string $id): void
28
    {
29 9
        if (!isset($this->carts[$id])) {
30 4
            throw new CartNotFoundException();
31
        }
32 7
    }
33
34 2
    public function remove(string $id): void
35
    {
36 2
        $this->checkExistence($id);
37 1
        unset($this->carts[$id]);
38 1
    }
39
}
40