Users::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
ccs 4
cts 4
cp 1
crap 2
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
The type Germania\Users\ArrayIterator was not found. Did you mean ArrayIterator? If so, make sure to prefix the type with \.
Loading history...
46
     * @uses   $users
47
     */
48 10
    public function getIterator()
49
    {
50 10
        return new \ArrayIterator( $this->users );
0 ignored issues
show
Bug Best Practice introduced by
The expression return new ArrayIterator($this->users) returns the type ArrayIterator which is incompatible with the documented return type Germania\Users\ArrayIterator.
Loading history...
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