Completed
Pull Request — development (#546)
by Nick
06:21
created

UserProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
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