• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

webeweb / jquery-datatables-bundle / 19800321758

30 Nov 2025 02:28PM UTC coverage: 99.666% (-0.1%) from 99.814%
19800321758

push

github

webeweb
Update GitHub action:
- restore Symfony 6.3

3581 of 3593 relevant lines covered (99.67%)

32.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/lib/common/Security/Core/User/UserHelper.php
1
<?php
2

3
/*
4
 * This file is part of the jquery-datatables-bundle package.
5
 *
6
 * (c) 2018 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
declare(strict_types = 1);
13

14
namespace WBW\Bundle\CommonBundle\Security\Core\User;
15

16
use Symfony\Component\HttpKernel\Kernel;
17
use Symfony\Component\Security\Core\User\UserInterface;
18

19
/**
20
 * User helper.
21
 *
22
 * @author webeweb <https://github.com/webeweb>
23
 * @package WBW\Bundle\CommonBundle\Security\Core\User
24
 */
25
class UserHelper {
26

27
    /**
28
     * Get the identifier.
29
     *
30
     * @param UserInterface $user The user.
31
     * @return string|null Returns the identifier.
32
     */
33
    public static function getIdentifier(UserInterface $user): ?string {
34

35
        // TODO: Remove when dropping support for Symfony 5
36
        if (Kernel::MAJOR_VERSION < 6) {
9✔
37
            return $user->getUsername();
9✔
38
        }
39

40
        return $user->getUserIdentifier();
×
41
    }
42

43
    /**
44
     * Determine if the connected user entity has roles.
45
     *
46
     * @param UserInterface|null $user The user.
47
     * @param array<mixed>|string|null $roles The role or roles.
48
     * @param bool $or OR ? If true, matches a role cause a break and the method returns true.
49
     * @return bool Returns true in case of success, false otherwise.
50
     */
51
    public static function hasRoles(?UserInterface $user, $roles, bool $or = true): bool {
52

53
        if (null === $user || null === $roles) {
3✔
54
            return false;
3✔
55
        }
56

57
        if (true === is_string($roles)) {
3✔
58
            $roles = [$roles];
3✔
59
        }
60

61
        $result = 1 <= count($roles);
3✔
62

63
        foreach ($roles as $role) {
3✔
64

65
            $buffer = in_array($role, $user->getRoles());
3✔
66

67
            if (true === $buffer && true === $or) {
3✔
68
                return true;
3✔
69
            }
70

71
            $result = $result && $buffer;
3✔
72
        }
73

74
        return $result;
3✔
75
    }
76
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc