Test Failed
Push — main ( d55b52...b5ed50 )
by Jean-Christophe
03:55
created

AclListQueryTrait   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 24
c 2
b 0
f 1
dl 0
loc 64
ccs 0
cts 18
cp 0
rs 10
wmc 13

5 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 existAclIn() 0 6 2
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
	 *
51
	 * @param AbstractAclPart $part
52
	 * @param string $providerClass
53
	 * @return boolean
54
	 */
55
	public function existPartIn(AbstractAclPart $part, string $providerClass) {
0 ignored issues
show
Bug introduced by
The type Ubiquity\security\acl\mo...\traits\AbstractAclPart was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
56
		$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

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