Completed
Push — master ( d1eae8...f6867f )
by Luc
14s
created

OwnerVoter::isAllowed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
1
<?php
2
3
namespace CultuurNet\UDB3\Offer\Security\Permission;
4
5
use CultuurNet\UDB3\Offer\ReadModel\Permission\PermissionQueryInterface;
6
use CultuurNet\UDB3\Role\ValueObjects\Permission;
7
use ValueObjects\StringLiteral\StringLiteral;
8
9
class OwnerVoter implements PermissionVoterInterface
10
{
11
    /**
12
     * @var PermissionQueryInterface
13
     */
14
    private $permissionRepository;
15
16
    /**
17
     * @param PermissionQueryInterface $permissionRepository
18
     */
19
    public function __construct(PermissionQueryInterface $permissionRepository)
20
    {
21
        $this->permissionRepository = $permissionRepository;
22
    }
23
24
    /**
25
     * @param Permission $permission
26
     * @param StringLiteral $offerId
27
     * @param StringLiteral $userId
28
     * @return bool
29
     */
30
    public function isAllowed(
31
        Permission $permission,
32
        StringLiteral $offerId,
33
        StringLiteral $userId
34
    ) {
35
        $editableEvents = $this->permissionRepository->getEditableOffers($userId);
36
        return in_array($offerId, $editableEvents);
37
    }
38
}
39