Test Failed
Push — main ( 43938e...353eb1 )
by Jean-Christophe
02:09
created

AclListOperationsTrait::removeRole()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 4
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
 * Ubiquity\security\acl\models\traits$AclListOperations
9
 * This class is part of Ubiquity
10
 *
11
 * @author jc
12
 * @version 1.0.0
13
 *
14
 */
15
trait AclListOperationsTrait {
16
17
	public function saveAclElement(AclElement $aclElement) {
18
		foreach ($this->providers as $provider) {
19
			$provider->saveAcl($aclElement);
20
		}
21
	}
22
23
	public function removeAclElement(AclElement $aclElement) {
24
		foreach ($this->providers as $provider) {
25
			$provider->removeAcl($aclElement);
26
		}
27
	}
28
29
	public function savePart(AbstractAclPart $aclPart) {
30
		foreach ($this->providers as $provider) {
31
			$provider->savePart($aclPart);
32
		}
33
	}
34
35
	public function updatePart(AbstractAclPart $aclPart) {
36
		foreach ($this->providers as $provider) {
37
			$provider->updatePart($aclPart);
38
		}
39
	}
40
41
	public function removePart(AbstractAclPart $aclPart) {
42
		foreach ($this->providers as $provider) {
43
			$provider->removePart($aclPart);
44
		}
45
	}
46
47
	public function removeRole(string $roleName) {
48
		$role = $this->getRoleByName($roleName);
0 ignored issues
show
Bug introduced by
It seems like getRoleByName() 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

48
		/** @scrutinizer ignore-call */ 
49
  $role = $this->getRoleByName($roleName);
Loading history...
49
		unset($this->roles["role_$roleName"]);
50
		$this->removePart($role);
51
	}
52
53
	public function removePermission(string $permissionName) {
54
		$permission = $this->getPermissionByName($permissionName);
0 ignored issues
show
Bug introduced by
It seems like getPermissionByName() 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

54
		/** @scrutinizer ignore-call */ 
55
  $permission = $this->getPermissionByName($permissionName);
Loading history...
55
		unset($this->permissions["perm_$permissionName"]);
56
		$this->removePart($permission);
57
	}
58
59
	public function removeResource(string $resourceName) {
60
		$resource = $this->getResourceByName($resourceName);
0 ignored issues
show
Bug introduced by
It seems like getResourceByName() 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

60
		/** @scrutinizer ignore-call */ 
61
  $resource = $this->getResourceByName($resourceName);
Loading history...
61
		unset($this->resources["res_$resourceName"]);
62
		$this->removePart($resource);
63
	}
64
65
	public function removeAcl(string $roleName, string $resourceName, string $permissionName = null) {
66
		$toRemove = [];
67
		foreach ($this->acls as $index => $acl) {
68
			if ($acl->getResource()->getName() === $resourceName && $acl->getRole()->getName() === $roleName) {
69
				if ($permissionName == null || $acl->getPermission()->getName() === $permissionName) {
70
					foreach ($this->providers as $provider) {
71
						$provider->removeAcl($acl);
72
					}
73
					$toRemove[] = $index;
74
				}
75
			}
76
		}
77
		foreach ($toRemove as $remove) {
78
			unset($this->acls[$remove]);
79
		}
80
	}
81
82
	public function saveAll() {
83
		foreach ($this->providers as $provider) {
84
			if (! $provider->isAutosave()) {
85
				$provider->saveAll();
86
			}
87
		}
88
	}
89
}
90
91