RuleResult::getId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace SimpleAcl;
4
5
use SimpleAcl\Resource\ResourceAggregateInterface;
6
use SimpleAcl\Role\RoleAggregateInterface;
7
8
/**
9
 * Returned as result of Rule::isAllowed
10
 *
11
 * @package SimpleAcl
12
 */
13
class RuleResult
14
{
15
  /**
16
   * @var Rule
17
   */
18
  protected $rule;
19
20
  /**
21
   * @var string
22
   */
23
  protected $needRoleName;
24
25
  /**
26
   * @var string
27
   */
28
  protected $needResourceName;
29
30
  /**
31
   * @var int
32
   */
33
  protected $id;
34
35
  /**
36
   * @var mixed
37
   */
38
  protected $action;
39
40
  /**
41
   * @var bool
42
   */
43
  protected $isInit = false;
44
45
  /**
46
   * @param Rule        $rule
47
   * @param string|null $needRoleName
48
   * @param string|null $needResourceName
49 31
   */
50
  public function __construct(Rule $rule, $needRoleName, $needResourceName)
51 31
  {
52
    static $idCountRuleResultSimpleAcl = 1;
53 31
54 31
    $this->id = $idCountRuleResultSimpleAcl++;
55 31
    $this->rule = $rule;
56 31
    $this->needRoleName = $needRoleName;
57 31
    $this->needResourceName = $needResourceName;
58
  }
59
60
  /**
61
   * @return string
62 2
   */
63
  public function getNeedResourceName(): string
64 2
  {
65
    return $this->needResourceName;
66
  }
67
68
  /**
69
   * @return string
70 2
   */
71
  public function getNeedRoleName(): string
72 2
  {
73
    return $this->needRoleName;
74
  }
75
76
  /**
77
   * @return Rule
78 27
   */
79
  public function getRule(): Rule
80 27
  {
81
    return $this->rule;
82
  }
83
84
  /**
85
   * @return mixed
86 27
   */
87
  public function getAction()
88 27
  {
89 27
    if (!$this->isInit) {
90 27
      $this->action = $this->getRule()->getAction($this);
91 27
      $this->isInit = true;
92
    }
93 27
94
    return $this->action;
95
  }
96
97
  /**
98
   * @return int
99 1
   */
100
  public function getId(): int
101 1
  {
102
    return $this->id;
103
  }
104
105
  /**
106
   * @return ResourceAggregateInterface
107 2
   */
108
  public function getResourceAggregate(): ResourceAggregateInterface
109 2
  {
110
    return $this->getRule()->getResourceAggregate();
111
  }
112
113
  /**
114
   * @return RoleAggregateInterface
115 2
   */
116
  public function getRoleAggregate(): RoleAggregateInterface
117 2
  {
118
    return $this->getRule()->getRoleAggregate();
119
  }
120
}
121