InMemoryAuthenticator::authenticate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Scheduler\Domain\Model\User;
4
5
class InMemoryAuthenticator implements Authenticator
6
{
7
    private $userMapper;
8
9
    private $tokenMap;
10
11
    public function __construct(UserMapper $userMapper, array $tokenMap)
12
    {
13
        $this->userMapper = $userMapper;
14
        $this->tokenMap = $tokenMap;
15
    }
16
17
    public function authenticate($token)
18
    {
19
        if (! array_key_exists($token, $this->tokenMap)) {
20
            return new NullUser();
21
        }
22
23
        $id = $this->tokenMap[$token];
24
        $user = $this->userMapper->find($id);
25
        $user->authenticate();
26
27
        return $user;
28
    }
29
}
30