Completed
Push — master ( 959e79...856e20 )
by Jan
06:43
created

GroupVoter::voteOnUser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 7
rs 10
1
<?php
2
/**
3
 *
4
 * part-db version 0.1
5
 * Copyright (C) 2005 Christoph Lechner
6
 * http://www.cl-projects.de/
7
 *
8
 * part-db version 0.2+
9
 * Copyright (C) 2009 K. Jacobs and others (see authors.php)
10
 * http://code.google.com/p/part-db/
11
 *
12
 * Part-DB Version 0.4+
13
 * Copyright (C) 2016 - 2019 Jan Böhmer
14
 * https://github.com/jbtronics
15
 *
16
 * This program is free software; you can redistribute it and/or
17
 * modify it under the terms of the GNU General Public License
18
 * as published by the Free Software Foundation; either version 2
19
 * of the License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
29
 *
30
 */
31
32
namespace App\Security\Voter;
33
34
35
use App\Entity\UserSystem\Group;
36
use App\Entity\UserSystem\User;
37
38
class GroupVoter extends ExtendedVoter
39
{
40
41
    /**
42
     * Similar to voteOnAttribute, but checking for the anonymous user is already done.
43
     * The current user (or the anonymous user) is passed by $user.
44
     *
45
     * @param $attribute
46
     * @param $subject
47
     * @param User $user
48
     *
49
     * @return bool
50
     */
51
    protected function voteOnUser($attribute, $subject, User $user): bool
52
    {
53
        if ($subject instanceof Group) {
54
            return $this->resolver->inherit($user,'groups', $attribute) ?? false;
55
        }
56
57
        return false;
58
    }
59
60
    /**
61
     * Determines if the attribute and subject are supported by this voter.
62
     *
63
     * @param string $attribute An attribute
64
     * @param mixed $subject The subject to secure, e.g. an object the user wants to access or any other PHP type
65
     *
66
     * @return bool True if the attribute and subject are supported, false otherwise
67
     */
68
    protected function supports($attribute, $subject)
69
    {
70
        if ($subject instanceof Group) {
71
            return $this->resolver->isValidOperation('groups', $attribute);
72
        }
73
74
        return false;
75
    }
76
}