Test Failed
Push — main ( 85a925...1676fa )
by Jean-Christophe
02:18
created

AclListQueryTrait::getAclsWithRole()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 5
c 1
b 0
f 1
nc 3
nop 1
dl 0
loc 8
rs 10
1
<?php
2
namespace Ubiquity\security\acl\models\traits;
3
4
use Ubiquity\security\acl\models\AclElement;
5
6
/**
7
 *
8
 * @author jc
9
 * @property AclElement[] $acls
10
 */
11
trait AclListQueryTrait {
12
13
	abstract public function getRoleByName(string $name);
14
15
	abstract public function getResourceByName(string $name);
16
17
	abstract public function getPermissionByName(string $name);
18
19
	public function getAclsWithRole(string $role) {
20
		$result = [];
21
		foreach ($this->acls as $acl) {
22
			if ($acl->getRole()->getName() === $role) {
23
				$result[] = $acl;
24
			}
25
		}
26
		return $result;
27
	}
28
29
	public function getAclsWithResource(string $resource) {
30
		$result = [];
31
		foreach ($this->acls as $acl) {
32
			if ($acl->getResource()->getName() === $resource) {
33
				$result[] = $acl;
34
			}
35
		}
36
		return $result;
37
	}
38
39
	public function getAclsWithPermission(string $permission) {
40
		$result = [];
41
		foreach ($this->acls as $acl) {
42
			if ($acl->getPermission()->getName() === $permission) {
43
				$result[] = $acl;
44
			}
45
		}
46
		return $result;
47
	}
48
}
49
50