Completed
Push — master ( ca7ebd...ffd42a )
by Nikolas
03:40
created

GenericAccessPolicy   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 52
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A isPermitted() 0 3 2
A isExecutionPemitted() 0 3 2
A denyAccess() 0 4 1
A denyExecutionWith() 0 4 1
1
<?php
2
namespace rtens\domin\execution\access;
3
4
class GenericAccessPolicy implements AccessPolicy {
5
6
    /** @var string */
7
    private $actionId;
8
9
    /** @var bool */
10
    private $accessPermitted = true;
11
12
    /** @var array[] */
13
    private $forbiddenParameters = [];
14
15
    /**
16
     * @param string $actionId
17
     */
18
    public function __construct($actionId) {
19
        $this->actionId = $actionId;
20
    }
21
22
    /**
23
     * @param string $actionId
24
     * @return boolean
25
     */
26
    public function isPermitted($actionId) {
27
        return $this->accessPermitted || $actionId != $this->actionId;
28
    }
29
30
    /**
31
     * @param string $actionId
32
     * @param array $parameters
33
     * @return bool
34
     */
35
    public function isExecutionPemitted($actionId, array $parameters) {
36
        return  $actionId != $this->actionId || !in_array($parameters, $this->forbiddenParameters);
37
    }
38
39
    /**
40
     * @return static
41
     */
42
    public function denyAccess() {
43
        $this->accessPermitted = false;
44
        return $this;
45
    }
46
47
    /**
48
     * @param array $parameters
49
     * @return static
50
     */
51
    public function denyExecutionWith(array $parameters) {
52
        $this->forbiddenParameters[] = $parameters;
53
        return $this;
54
    }
55
}