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

AclElement   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 40%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
dl 0
loc 68
ccs 10
cts 25
cp 0.4
rs 10
c 1
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 10 1
A getPermission() 0 2 1
A getRole() 0 2 1
A allow() 0 4 1
A toArray() 0 5 1
A getResource() 0 2 1
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