Completed
Pull Request — development (#546)
by Nick
07:54 queued 01:05
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
 * @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