Passed
Push — master ( 6f214c...ffcc9b )
by WEBEWEB
13:06
created

UserHelper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 4
c 1
b 0
f 0
dl 0
loc 15
rs 10
ccs 3
cts 3
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A getIdentifier() 0 7 2
1
<?php
2
3
/*
4
 * This file is part of the core-bundle package.
5
 *
6
 * (c) 2023 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\CoreBundle\Helper;
13
14
use Symfony\Component\HttpKernel\Kernel;
15
use Symfony\Component\Security\Core\User\UserInterface;
16
17
/**
18
 * User helper.
19
 *
20
 * @author webeweb <https://github.com/webeweb>
21
 * @package WBW\Bundle\CoreBundle\Tests\Helper
22
 */
23
class UserHelper {
24
25
    /**
26
     * Get the identifier.
27
     *
28
     * @param UserInterface $user The user.
29
     * @return string|null Returns the identifier.
30
     */
31
    public static function getIdentifier(UserInterface $user): ?string {
32 30
33
        if (6 <= Kernel::MAJOR_VERSION) {
34 30
            return $user->getUserIdentifier();
35 20
        }
36
37
        return $user->getUsername();
0 ignored issues
show
Bug introduced by
The method getUsername() does not exist on Symfony\Component\Security\Core\User\UserInterface. It seems like you code against a sub-type of Symfony\Component\Security\Core\User\UserInterface such as WBW\Bundle\CoreBundle\Model\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

37
        return $user->/** @scrutinizer ignore-call */ getUsername();
Loading history...
38 20
    }
39
}
40