Total Complexity | 17 |
Total Lines | 59 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class InMemoryUserRepository implements UserRepository |
||
11 | { |
||
12 | private $users = []; |
||
13 | |||
14 | public function add(User $u, string $password = null) |
||
15 | { |
||
16 | $this->users[] = $u; |
||
17 | } |
||
18 | |||
19 | public function getByEmail(string $email):?User |
||
27 | } |
||
28 | |||
29 | public function getById(string $id):?User |
||
30 | { |
||
31 | foreach ($this->users as $user){ |
||
32 | if($user->id() === $id){ |
||
33 | return $user; |
||
34 | } |
||
35 | } |
||
36 | return null; |
||
37 | } |
||
38 | |||
39 | public function search(string $organizationId, int $page, int $perPage = 10): array |
||
40 | { |
||
41 | $users = []; |
||
42 | foreach($this->users as $user){ |
||
43 | if($user->organizationId() === $organizationId){ |
||
44 | $users[] = $user; |
||
45 | } |
||
46 | } |
||
47 | $chunks = array_chunk($users, $perPage); |
||
48 | $list = isset($chunks[$page-1]) ? $chunks[$page-1] : []; |
||
49 | return [ |
||
50 | 'list' => $list, |
||
51 | 'total' => count($users) |
||
52 | ]; |
||
53 | } |
||
54 | |||
55 | public function update(User $u) |
||
60 | } |
||
61 | } |
||
62 | } |
||
63 | |||
64 | public function delete(string $userId) |
||
73 |