AclListQueryTrait   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 23.53%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 29
dl 0
loc 76
ccs 8
cts 34
cp 0.2353
rs 10
c 3
b 0
f 1
wmc 17

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getAclsWithPermission() 0 8 3
A getAclsWithRole() 0 8 3
A getAclsWithResource() 0 8 3
A existPartIn() 0 6 2
A getRolesWithPermissionOnResource() 0 8 4
A existAclIn() 0 6 2
1
<?php
2
namespace Ubiquity\security\acl\models\traits;
3
4
use Ubiquity\security\acl\models\AclElement;
5
use Ubiquity\security\acl\models\AbstractAclPart;
6
7
/**
8
 *
9
 * @author jc
10
 * @property AclElement[] $acls
11
 */
12
trait AclListQueryTrait {
13
14
	abstract public function getRoleByName(string $name);
15
16
	abstract public function getResourceByName(string $name);
17
18
	abstract public function getPermissionByName(string $name);
19
20
	abstract public function getProvider(string $providerClass);
21
22
	public function getAclsWithRole(string $role) {
23
		$result = [];
24
		foreach ($this->acls as $acl) {
25
			if ($acl->getRole()->getName() === $role) {
26
				$result[] = $acl;
27
			}
28
		}
29
		return $result;
30
	}
31
32
	public function getAclsWithResource(string $resource) {
33
		$result = [];
34
		foreach ($this->acls as $acl) {
35
			if ($acl->getResource()->getName() === $resource) {
36
				$result[] = $acl;
37
			}
38
		}
39
		return $result;
40
	}
41
42
	public function getAclsWithPermission(string $permission) {
43
		$result = [];
44
		foreach ($this->acls as $acl) {
45
			if ($acl->getPermission()->getName() === $permission) {
46
				$result[] = $acl;
47
			}
48
		}
49
		return $result;
50
	}
51
52
	public function getRolesWithPermissionOnResource(string $resource, string $permission) {
53
		$result = [];
54
		foreach ($this->acls as $acl) {
55
			if ($acl->getPermission()->getName() === $permission && $acl->getResource()->getName() === $resource) {
56
				$result[] = $acl->getRole()->getName();
57
			}
58
		}
59
		return $result;
60
	}
61
62
	/**
63
	 *
64
	 * @param AbstractAclPart $part
65
	 * @param string $providerClass
66
	 * @return boolean
67
	 */
68 2
	public function existPartIn(AbstractAclPart $part, string $providerClass) {
69 2
		$prov = $this->getProvider($providerClass);
70 2
		if (isset($prov)) {
71 2
			return $prov->existPart($part);
72
		}
73
		return false;
74
	}
75
76
	/**
77
	 *
78
	 * @param AclElement $elm
79
	 * @param string $providerClass
80
	 * @return boolean
81
	 */
82 2
	public function existAclIn(AclElement $elm, string $providerClass) {
83 2
		$prov = $this->getProvider($providerClass);
84 2
		if (isset($prov)) {
85 2
			return $prov->existAcl($elm);
86
		}
87
		return false;
88
	}
89
}
90
91