Passed
Push — main ( e591c1...2428da )
by Jean-Christophe
02:42
created

AclElement::fromArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 10
ccs 0
cts 10
cp 0
crap 2
rs 9.9666
c 0
b 0
f 0
1
<?php
2
namespace Ubiquity\security\acl\models;
3
4
class AclElement {
5
6
	/**
7
	 *
8
	 * @var Role
9
	 */
10
	protected $role;
11
12
	/**
13
	 *
14
	 * @var Permission
15
	 */
16
	protected $permission;
17
18
	/**
19
	 *
20
	 * @var \Ubiquity\security\acl\models\Resource
21
	 */
22
	protected $resource;
23
24
	/**
25
	 *
26
	 * @return Role
27
	 */
28 3
	public function getRole() {
29 3
		return $this->role;
30
	}
31
32
	/**
33
	 *
34
	 * @return Permission
35
	 */
36 2
	public function getPermission() {
37 2
		return $this->permission;
38
	}
39
40
	/**
41
	 *
42
	 * @return \Ubiquity\security\acl\models\Resource
43
	 */
44 3
	public function getResource() {
45 3
		return $this->resource;
46
	}
47
48
	public function fromArray($aclArray) {
49
		$role = new Role();
50
		$role->fromArray($aclArray['role']);
51
		$resource = new Resource();
52
		$resource->fromArray($aclArray['resource']);
53
		$permission = new Permission();
54
		$permission->fromArray($aclArray['permission']);
55
		$this->role = $role;
56
		$this->permission = $permission;
57
		$this->resource = $resource;
58
	}
59
60
	public function toArray(): array {
61
		return [
62
			'resource' => $this->resource->toArray(),
63
			'role' => $this->role->toArray(),
64
			'permission' => $this->permission->toArray()
65
		];
66
	}
67
68 3
	public function allow(Role $role, Resource $resource, Permission $permission) {
69 3
		$this->role = $role;
70 3
		$this->resource = $resource;
71 3
		$this->permission = $permission;
72 3
	}
73
}
74
75