Passed
Pull Request — master (#6396)
by Angel Fernando Quiroz
13:45 queued 05:26
created

UserHelper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 12
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCurrent() 0 6 2
A __construct() 0 3 1
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
namespace Chamilo\CoreBundle\Helpers;
8
9
use Chamilo\CoreBundle\Entity\User;
10
use Symfony\Bundle\SecurityBundle\Security;
11
use Symfony\Component\Security\Core\User\UserInterface;
12
13
readonly class UserHelper
14
{
15
    public function __construct(
16
        private Security $security,
17
    ) {}
18
19
    public function getCurrent(): ?User
20
    {
21
        /** @var User|null $user */
22
        $user = $this->security->getUser();
23
24
        return $user instanceof UserInterface ? $user : null;
25
    }
26
}
27