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

ApplicationUserEventSourcedRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

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\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