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