UserCallableHelper::getCurrentUser()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 6
nc 3
nop 0
1
<?php
2
3
namespace Victoire\Bundle\PageBundle\Helper;
4
5
use Symfony\Component\DependencyInjection\Container;
6
7
/**
8
 * @author Paul Andrieux
9
 */
10
class UserCallableHelper
11
{
12
    /**
13
     * @var Container
14
     */
15
    private $container;
16
17
    /**
0 ignored issues
show
introduced by
Doc comment for parameter "$container" missing
Loading history...
18
     * Constructor.
19
     */
20
    public function __construct(Container $container)
21
    {
22
        $this->container = $container;
23
    }
24
25
    /**
26
     * Get the current user.
27
     *
28
     * @return null
29
     */
30
    public function getCurrentUser()
31
    {
32
        $userClass = $this->container->getParameter('victoire_core.user_class');
33
        $token = $this->container->get('security.context')->getToken();
34
35
        if ($token !== null) {
36
            if ($token->getUser() instanceof $userClass) {
37
                return $token->getUser();
38
            }
39
        }
40
    }
41
}
42