Completed
Branch master (458557)
by T
02:07
created

Statement::getResource()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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 12
    public function __construct($statement)
25
    {
26 12
        if (!isset($statement['Action'])) {
27 2
            throw new \InvalidArgumentException('Missing required field Action.');
28
        }
29
30 10
        if (!isset($statement['Resource'])) {
31 1
            throw new \InvalidArgumentException('Missing required field Resource.');
32
        }
33
34 9
        if (!isset($statement['Effect'])) {
35 1
            throw new \InvalidArgumentException('Missing required field Effect.');
36
        }
37
38 8
        $this->action = new Action($statement['Action']);
39 8
        $this->resource = new Resource($statement['Resource']);
40 8
        $this->effect = new Effect($statement['Effect']);
41 8
    }
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 4
    public function getEffect()
63
    {
64 4
        return $this->effect;
65
    }
66
67
    /**
68
     * @param string $resource
69
     * @return bool
70
     */
71 5
    public function matchesResource($resource)
72
    {
73 5
        return $this->resource->matches($resource);
74
    }
75
76
    /**
77
     * @param string $action
78
     * @return bool
79
     */
80 6
    public function matchesAction($action)
81
    {
82 6
        return $this->action->matches($action);
83
    }
84
}
85