Completed
Push — master ( a822fd...f88949 )
by Rémi
05:42
created

ApplicationUserEventSourcedRepository::load()   A

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 2
Bugs 1 Features 0
Metric Value
c 2
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 MessageApp\User\Repository\EventSourced;
4
5
use Broadway\Domain\AggregateRoot;
6
use Broadway\EventSourcing\EventSourcingRepository;
7
use MessageApp\User\ApplicationUser;
8
use MessageApp\User\ApplicationUserId;
9
use MessageApp\User\Exception\AppUserException;
10
use MessageApp\User\Repository\ApplicationUserRepository;
11
12
class ApplicationUserEventSourcedRepository implements ApplicationUserRepository
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  ApplicationUser $user
33
     * @return void
34
     */
35 6
    public function save(ApplicationUser $user)
36
    {
37 6
        if (!$user instanceof AggregateRoot) {
38 3
            throw new \InvalidArgumentException();
39
        }
40
41 3
        $this->repository->save($user);
42 3
    }
43
44
    /**
45
     * Get the user corresponding to the id
46
     *
47
     * @param  ApplicationUserId $id
48
     * @throws AppUserException
49
     * @return ApplicationUser
50
     */
51 9
    public function load(ApplicationUserId $id)
52
    {
53 9
        $user = $this->repository->load($id);
54
55 9
        if ($user !== null && ! $user instanceof ApplicationUser) {
56 3
            throw new \InvalidArgumentException();
57
        }
58
59 6
        return $user;
60
    }
61
}
62