AclListQueryTrait::existAclIn()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 6
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
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