Completed
Pull Request — development (#546)
by Nick
07:54 queued 01:05
created

UserProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A bySession() 0 8 2
1
<?php
2
3
namespace Oc\User;
4
5
use Oc\Session\SessionDataInterface;
6
7
/**
8
 * Class UserProvider
9
 *
10
 * @package Oc\User
11
 * @author Nick Lubisch <[email protected]>
12
 */
13
class UserProvider
14
{
15
    /**
16
     * @var SessionDataInterface
17
     */
18
    private $sessionData;
19
20
    /**
21
     * @var UserService
22
     */
23
    private $userService;
24
25
    /**
26
     * UserProvider constructor.
27
     *
28
     * @param SessionDataInterface $sessionData
29
     * @param UserService $userService
30
     */
31
    public function __construct(SessionDataInterface $sessionData, UserService $userService)
32
    {
33
        $this->sessionData = $sessionData;
34
        $this->userService = $userService;
35
    }
36
37
    /**
38
     * Fetches the user by its session.
39
     *
40
     * @return UserEntity|null User entity or null if there is no userId in session or the user is not found
41
     */
42
    public function bySession()
43
    {
44
        if ($userId = $this->sessionData->get('userid')) {
45
            return $this->userService->fetchOneById($userId);
46
        }
47
48
        return null;
49
    }
50
}
51