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

Statement   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 80.95%

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 3
dl 0
loc 80
ccs 17
cts 21
cp 0.8095
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 18 4
A getAction() 0 4 1
A getResource() 0 4 1
A getEffect() 0 4 1
A matchesResource() 0 4 1
A matchesAction() 0 4 1
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