Completed
Pull Request — development (#546)
by Nick
06:21
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
 */
12
class UserProvider
13
{
14
    /**
15
     * @var SessionDataInterface
16
     */
17
    private $sessionData;
18
19
    /**
20
     * @var UserService
21
     */
22
    private $userService;
23
24
    /**
25
     * UserProvider constructor.
26
     *
27
     * @param SessionDataInterface $sessionData
28
     * @param UserService $userService
29
     */
30
    public function __construct(SessionDataInterface $sessionData, UserService $userService)
31
    {
32
        $this->sessionData = $sessionData;
33
        $this->userService = $userService;
34
    }
35
36
    /**
37
     * Fetches the user by its session.
38
     *
39
     * @return UserEntity|null User entity or null if there is no userId in session or the user is not found
40
     */
41
    public function bySession()
42
    {
43
        if ($userId = $this->sessionData->get('userid')) {
44
            return $this->userService->fetchOneById($userId);
45
        }
46
47
        return null;
48
    }
49
}
50