Completed
Push — master ( 34d9dc...4a4084 )
by Nikolas
03:09
created

GenericAccessRestriction::isExecutionRestricted()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 2
eloc 2
nc 2
nop 2
1
<?php
2
namespace rtens\domin\execution\access;
3
4
class GenericAccessRestriction implements AccessRestriction {
5
6
    /** @var string */
7
    private $actionId;
8
9
    /** @var bool */
10
    private $accessRestricted = false;
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 isRestricted($actionId) {
27
        return $actionId == $this->actionId && $this->accessRestricted;
28
    }
29
30
    /**
31
     * @param string $actionId
32
     * @param array $parameters
33
     * @return bool
34
     */
35
    public function isExecutionRestricted($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->accessRestricted = true;
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
}