Completed
Push — master ( a3cce1...d6fbcc )
by Marcel
09:39
created

ProfileVoter::voteOnAttribute()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4.25

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 1
b 0
f 0
nc 4
nop 3
dl 0
loc 14
ccs 6
cts 8
cp 0.75
crap 4.25
rs 10
1
<?php
2
3
namespace App\Security\Voter;
4
5
use App\Entity\User;
6
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
7
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
8
9
class ProfileVoter extends Voter {
10
11
    const CHANGE_PASSWORD = 'change_password';
12
    const USE_2FA = 'use_2fa';
13
14
    /**
15
     * @inheritDoc
16
     */
17 7
    protected function supports($attribute, $subject) {
18 7
        return in_array($attribute, [ static::CHANGE_PASSWORD, static::USE_2FA]);
19
    }
20
21
    /**
22
     * @inheritDoc
23
     */
24 5
    protected function voteOnAttribute($attribute, $subject, TokenInterface $token) {
25 5
        $user = $token->getUser();
26
27 5
        if(!$user instanceof User) {
28
            return false;
29
        }
30
31
        switch($attribute) {
32 5
            case static::CHANGE_PASSWORD:
33 5
            case static::USE_2FA:
34 5
                return $user->canChangePassword();
35
        }
36
37
        throw new \LogicException('This code should not be reached');
38
    }
39
}