Statement::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 11
cts 11
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 4
nop 1
crap 4
1
<?php
2
3
namespace tomzx\PolicyEvaluator;
4
5
class Statement
6
{
7
    /**
8
     * @var \tomzx\PolicyEvaluator\Action
9
     */
10
    private $action;
11
    /**
12
     * @var \tomzx\PolicyEvaluator\Resource
13
     */
14
    private $resource;
15
16
    /**
17
     * @var \tomzx\PolicyEvaluator\Effect
18
     */
19
    private $effect;
20
21
    /**
22
     * @param array $statement
23
     */
24 14
    public function __construct(array $statement)
25
    {
26 14
        if (!isset($statement['Action'])) {
27 2
            throw new \InvalidArgumentException('Missing required field Action.');
28
        }
29
30 12
        if (!isset($statement['Resource'])) {
31 1
            throw new \InvalidArgumentException('Missing required field Resource.');
32
        }
33
34 11
        if (!isset($statement['Effect'])) {
35 1
            throw new \InvalidArgumentException('Missing required field Effect.');
36
        }
37
38 10
        $this->action = new Action($statement['Action']);
39 10
        $this->resource = new Resource($statement['Resource']);
40 10
        $this->effect = new Effect($statement['Effect']);
41 10
    }
42
43
    /**
44
     * @return \tomzx\PolicyEvaluator\Action
45
     */
46
    public function getAction()
47
    {
48
        return $this->action;
49
    }
50
51
    /**
52
     * @return \tomzx\PolicyEvaluator\Resource
53
     */
54
    public function getResource()
55
    {
56
        return $this->resource;
57
    }
58
59
    /**
60
     * @return \tomzx\PolicyEvaluator\Effect
61
     */
62 6
    public function getEffect()
63
    {
64 6
        return $this->effect;
65
    }
66
67
    /**
68
     * @param string $resource
69
     * @param array $variables
70
     * @return bool
71
     */
72 7
    public function matchesResource($resource, array $variables = [])
73
    {
74 7
        return $this->resource->matches($resource, $variables);
75
    }
76
77
    /**
78
     * @param string $action
79
     * @return bool
80
     */
81 8
    public function matchesAction($action)
82
    {
83 8
        return $this->action->matches($action);
84
    }
85
}
86