MiniGameEventSourcedRepository::load()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

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