OrganisationVoter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 3
eloc 3
c 2
b 1
f 0
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 3 1
A voteOnAttribute() 0 3 2
1
<?php
2
3
/*
4
 * This file is part of the vseth-semesterly-reports project.
5
 *
6
 * (c) Florian Moser <[email protected]>
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 App\Security\Voter;
13
14
use App\Entity\Organisation;
15
use App\Model\User;
16
use App\Security\Voter\Base\BaseVoter;
17
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
18
19
class OrganisationVoter extends BaseVoter
20
{
21
    /**
22
     * @param string $attribute An attribute
23
     * @param mixed $subject The subject to secure, e.g. an object the user wants to access or any other PHP type
24
     *
25
     * @return bool True if the attribute and subject are supported, false otherwise
26
     */
27
    protected function supports($attribute, $subject)
28
    {
29
        return $subject instanceof Organisation;
30
    }
31
32
    /**
33
     * Perform a single access check operation on a given attribute, subject and token.
34
     * It is safe to assume that $attribute and $subject already passed the "supports()" method check.
35
     *
36
     * @param string $attribute
37
     * @param Organisation $subject
38
     *
39
     * @return bool
40
     */
41
    protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
42
    {
43
        return \in_array(User::ROLE_ADMIN, $token->getRoleNames(), true) || ($subject->getEmail() === $token->getUser()->getUsername());
0 ignored issues
show
Bug introduced by
The method getRoleNames() does not exist on Symfony\Component\Securi...on\Token\TokenInterface. Did you maybe mean getRoles()? ( Ignorable by Annotation )

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

43
        return \in_array(User::ROLE_ADMIN, $token->/** @scrutinizer ignore-call */ getRoleNames(), true) || ($subject->getEmail() === $token->getUser()->getUsername());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
44
    }
45
}
46