Completed
Push — master ( 26ff59...ba5821 )
by Rémi
03:04
created

UserEventSourcedRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace MessageApp\User\Repository\EventSourced;
4
5
use Broadway\Domain\AggregateRoot;
6
use Broadway\EventSourcing\EventSourcingRepository;
7
use MessageApp\Exception\MessageAppException;
8
use MessageApp\User\ApplicationUserId;
9
use MessageApp\User\Entity\SourcedUser;
10
use MessageApp\User\Repository\UserRepository;
11
12
class UserEventSourcedRepository implements UserRepository
13
{
14
    /**
15
     * @var EventSourcingRepository
16
     */
17
    private $repository;
18
19
    /**
20
     * Constructor
21
     *
22
     * @param EventSourcingRepository $repository
23
     */
24
    public function __construct(EventSourcingRepository $repository)
25
    {
26
        $this->repository = $repository;
27
    }
28
29
    /**
30
     * Saves a mini-game
31
     *
32
     * @param  SourcedUser $user
33
     *
34
     * @return void
35
     */
36
    public function save(SourcedUser $user)
37
    {
38
        if (!$user instanceof AggregateRoot) {
39
            throw new \InvalidArgumentException();
40
        }
41
42
        $this->repository->save($user);
43
    }
44
45
    /**
46
     * Get the user corresponding to the id
47
     *
48
     * @param  ApplicationUserId $id
49
     *
50
     * @throws MessageAppException
51
     * @return SourcedUser
52
     */
53
    public function load(ApplicationUserId $id)
54
    {
55
        $user = $this->repository->load($id);
56
57
        if ($user !== null && ! $user instanceof SourcedUser) {
58
            throw new \InvalidArgumentException();
59
        }
60
61
        return $user;
62
    }
63
}
64