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

GenericAccessPolicy::denyAccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 3
nc 1
nop 0
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
}