1 | <?php |
||
2 | namespace Germania\Users; |
||
3 | |||
4 | class Users implements UsersInterface |
||
5 | { |
||
6 | |||
7 | /** |
||
8 | * @var array |
||
9 | */ |
||
10 | public $users = array(); |
||
11 | |||
12 | |||
13 | public function __debugInfo() { |
||
14 | return [ |
||
15 | 'NumberOfUsers' => $this->count() |
||
16 | ]; |
||
17 | } |
||
18 | |||
19 | /** |
||
20 | * @return UserInterface |
||
21 | * @throws UserNotFoundException |
||
22 | * @uses $users |
||
23 | */ |
||
24 | 10 | public function get( $id ) |
|
25 | { |
||
26 | 10 | if ($this->has( $id )) { |
|
27 | 5 | return $this->users[ $id ]; |
|
28 | } |
||
29 | 5 | throw new UserNotFoundException("Could not find User with ID '$id'"); |
|
30 | } |
||
31 | |||
32 | |||
33 | /** |
||
34 | * @return boolean |
||
35 | * @uses $users |
||
36 | */ |
||
37 | 15 | public function has ($id ) |
|
38 | { |
||
39 | 15 | return array_key_exists( $id, $this->users); |
|
40 | } |
||
41 | |||
42 | |||
43 | |||
44 | /** |
||
45 | * @return ArrayIterator |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
46 | * @uses $users |
||
47 | */ |
||
48 | 10 | public function getIterator() |
|
49 | { |
||
50 | 10 | return new \ArrayIterator( $this->users ); |
|
0 ignored issues
–
show
|
|||
51 | } |
||
52 | |||
53 | |||
54 | /** |
||
55 | * @return int |
||
56 | * @uses $users |
||
57 | */ |
||
58 | 5 | public function count() |
|
59 | { |
||
60 | 5 | return count($this->users); |
|
61 | } |
||
62 | } |
||
63 |