Completed
Push — master ( bae43a...71580e )
by Lars
02:55
created

RuleResult::getNeedRoleName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 4
Bugs 1 Features 2
Metric Value
c 4
b 1
f 2
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace SimpleAcl;
3
4
use SimpleAcl\Resource\ResourceAggregateInterface;
5
use SimpleAcl\Role\RoleAggregateInterface;
6
7
/**
8
 * Returned as result of Rule::isAllowed
9
 *
10
 * @package SimpleAcl
11
 */
12
class RuleResult
13
{
14
  /**
15
   * @var Rule
16
   */
17
  protected $rule;
18
19
  /**
20
   * @var string
21
   */
22
  protected $needRoleName;
23
24
  /**
25
   * @var string
26
   */
27
  protected $needResourceName;
28
29
  /**
30
   * @var string
31
   */
32
  protected $id;
33
34
  /**
35
   * @var
36
   */
37
  protected $action;
38
39
  /**
40
   * @var bool
41
   */
42
  protected $isInit = false;
43
44
  /**
45
   * @param Rule $rule
46
   * @param      $needRoleName
47
   * @param      $needResourceName
48
   */
49 31
  public function __construct(Rule $rule, $needRoleName, $needResourceName)
50
  {
51 31
    static $idCountRuleResultSimpleAcl = 1;
52
53 31
    $this->id = $idCountRuleResultSimpleAcl++;
0 ignored issues
show
Documentation Bug introduced by
The property $id was declared of type string, but $idCountRuleResultSimpleAcl++ is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
54 31
    $this->rule = $rule;
55 31
    $this->needRoleName = $needRoleName;
56 31
    $this->needResourceName = $needResourceName;
57 31
  }
58
59
  /**
60
   * @return string
61
   */
62 2
  public function getNeedResourceName()
63
  {
64 2
    return $this->needResourceName;
65
  }
66
67
  /**
68
   * @return string
69
   */
70 2
  public function getNeedRoleName()
71
  {
72 2
    return $this->needRoleName;
73
  }
74
75
  /**
76
   * @return Rule
77
   */
78 27
  public function getRule()
79
  {
80 27
    return $this->rule;
81
  }
82
83
  /**
84
   * @return bool
85
   */
86 27
  public function getAction()
87
  {
88 27
    if (!$this->isInit) {
89 27
      $this->action = $this->getRule()->getAction($this);
90 27
      $this->isInit = true;
91 27
    }
92
93 27
    return $this->action;
94
  }
95
96
  /**
97
   * @return string
98
   */
99 1
  public function getId()
100
  {
101 1
    return $this->id;
102
  }
103
104
  /**
105
   * @return ResourceAggregateInterface
106
   */
107 2
  public function getResourceAggregate()
108
  {
109 2
    return $this->getRule()->getResourceAggregate();
110
  }
111
112
  /**
113
   * @return RoleAggregateInterface
114
   */
115 2
  public function getRoleAggregate()
116
  {
117 2
    return $this->getRule()->getRoleAggregate();
118
  }
119
}
120