IsUserHimselfVoter   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 20
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 3 2
A voteOnAttribute() 0 5 3
1
<?php
2
declare(strict_types = 1);
3
/**
4
 * /src/Security/Voter/IsUserHimselfVoter.php
5
 *
6
 * @author TLe, Tarmo Leppänen <[email protected]>
7
 */
8
9
namespace App\Security\Voter;
10
11
use App\Entity\User;
12
use App\Security\SecurityUser;
13
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
14
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
15
16
/**
17
 * Class IsUserHimselfVoter
18
 *
19
 * @package App\Security
20
 * @author TLe, Tarmo Leppänen <[email protected]>
21
 *
22
 * @template TAttribute of string
23
 * @template TSubject of mixed
24
 *
25
 * @extends Voter<TAttribute, TSubject>
26
 */
27
class IsUserHimselfVoter extends Voter
28
{
29
    private const ATTRIBUTE = 'IS_USER_HIMSELF';
30
31
    /**
32
     * {@inheritdoc}
33
     */
34 246
    protected function supports(string $attribute, mixed $subject): bool
35
    {
36 246
        return $attribute === self::ATTRIBUTE && $subject instanceof User;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42 27
    protected function voteOnAttribute(string $attribute, mixed $subject, TokenInterface $token): bool
43
    {
44 27
        $user = $token->getUser();
45
46 27
        return $user instanceof SecurityUser && $subject instanceof User && $user->getUuid() === $subject->getId();
47
    }
48
}
49