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

OwnerVoter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isAllowed() 0 8 1
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