Completed
Push — master ( f7f222...74e4e6 )
by Rémi
02:50
created

ApplicationUserEventSourcedRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 92.31%

Importance

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

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 MessageApp\User\Repository\EventSourced;
4
5
use Broadway\Domain\AggregateRoot;
6
use Broadway\EventSourcing\EventSourcingRepository;
7
use MessageApp\User\ApplicationUserId;
8
use MessageApp\User\Entity\SourcedUser;
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 12
    public function __construct(EventSourcingRepository $repository)
25
    {
26 12
        $this->repository = $repository;
27 12
    }
28
29
    /**
30
     * Saves a mini-game
31
     *
32
     * @param  SourcedUser $user
33
     *
34
*@return void
35
     */
36 3
    public function save(SourcedUser $user)
37
    {
38 3
        if (!$user instanceof AggregateRoot) {
39
            throw new \InvalidArgumentException();
40
        }
41
42 3
        $this->repository->save($user);
43 3
    }
44
45
    /**
46
     * Get the user corresponding to the id
47
     *
48
     * @param  ApplicationUserId $id
49
     *
50
*@throws AppUserException
51
     * @return SourcedUser
52
     */
53 9
    public function load(ApplicationUserId $id)
54
    {
55 9
        $user = $this->repository->load($id);
56
57 9
        if ($user !== null && ! $user instanceof SourcedUser) {
58 3
            throw new \InvalidArgumentException();
59
        }
60
61 6
        return $user;
62
    }
63
}
64