MiniGameEventSourcedRepository   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A save() 0 8 2
A load() 0 10 3
1
<?php
2
3
namespace MiniGameApp\Repository\EventSourced;
4
5
use Broadway\Domain\AggregateRoot;
6
use Broadway\EventSourcing\EventSourcingRepository;
7
use MiniGame\Entity\MiniGame;
8
use MiniGame\Entity\MiniGameId;
9
use MiniGameApp\Exception\GameNotFoundException;
10
use MiniGameApp\Repository\GameRepository;
11
12
class MiniGameEventSourcedRepository implements GameRepository
13
{
14
    /**
15
     * @var EventSourcingRepository
16
     */
17
    private $repository;
18
19
    /**
20
     * Constructor
21
     *
22
     * @param EventSourcingRepository $repository
23
     */
24 15
    public function __construct(EventSourcingRepository $repository)
25
    {
26 15
        $this->repository = $repository;
27 15
    }
28
29
    /**
30
     * Saves a mini-game
31
     *
32
     * @param  MiniGame $game
33
     * @return MiniGame
34
     */
35 6
    public function save(MiniGame $game)
36
    {
37 6
        if (!$game instanceof AggregateRoot) {
38 3
            throw new \InvalidArgumentException();
39
        }
40
41 3
        $this->repository->save($game);
42 3
    }
43
44
    /**
45
     * Get the mini-game corresponding to the id
46
     *
47
     * @param  MiniGameId $id
48
     * @throws GameNotFoundException
49
     * @return MiniGame
50
     */
51 9
    public function load(MiniGameId $id)
52
    {
53 9
        $game = $this->repository->load($id);
54
55 9
        if ($game !== null && ! $game instanceof MiniGame) {
56 3
            throw new \InvalidArgumentException();
57
        }
58
59 6
        return $game;
60
    }
61
}
62