Passed
Push — main ( b9df1c...66c5b2 )
by Jean-Christophe
02:06
created

AclListQueryTrait::getAclsWithPermission()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

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
ccs 0
cts 6
cp 0
crap 12
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
	public function getAclsWithRole(string $role) {
21
		$result = [];
22
		foreach ($this->acls as $acl) {
23
			if ($acl->getRole()->getName() === $role) {
24
				$result[] = $acl;
25
			}
26
		}
27
		return $result;
28
	}
29
30
	public function getAclsWithResource(string $resource) {
31
		$result = [];
32
		foreach ($this->acls as $acl) {
33
			if ($acl->getResource()->getName() === $resource) {
34
				$result[] = $acl;
35
			}
36
		}
37
		return $result;
38
	}
39
40
	public function getAclsWithPermission(string $permission) {
41
		$result = [];
42
		foreach ($this->acls as $acl) {
43
			if ($acl->getPermission()->getName() === $permission) {
44
				$result[] = $acl;
45
			}
46
		}
47
		return $result;
48
	}
49
50
	/**
51
	 *
52
	 * @param AbstractAclPart $part
53
	 * @param string $providerClass
54
	 * @return boolean
55
	 */
56 2
	public function existPartIn(AbstractAclPart $part, string $providerClass) {
57 2
		$prov = $this->getProvider($providerClass);
0 ignored issues
show
Bug introduced by
It seems like getProvider() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
		/** @scrutinizer ignore-call */ 
58
  $prov = $this->getProvider($providerClass);
Loading history...
58 2
		if (isset($prov)) {
59 2
			return $prov->existPart($part);
60
		}
61
		return false;
62
	}
63
64
	/**
65
	 *
66
	 * @param AclElement $elm
67
	 * @param string $providerClass
68
	 * @return boolean
69
	 */
70 2
	public function existAclIn(AclElement $elm, string $providerClass) {
71 2
		$prov = $this->getProvider($providerClass);
72 2
		if (isset($prov)) {
73 2
			return $prov->existAcl($elm);
74
		}
75
		return false;
76
	}
77
}
78
79