Passed
Push — main ( 280cf4...2747d9 )
by Jean-Christophe
02:02
created

AclArrayProvider   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 96.3%

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 67
ccs 26
cts 27
cp 0.963
rs 10
c 0
b 0
f 0
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A loadAllRoles() 0 2 1
A __construct() 0 1 1
A loadAllResources() 0 2 1
A loadAllAcls() 0 8 2
A loadAllPermissions() 0 2 1
A _saveAcl() 0 2 1
A _savePart() 0 3 1
A loadAllPart() 0 8 2
1
<?php
2
namespace Ubiquity\security\acl\persistence;
3
4
use Ubiquity\security\acl\models\AclElement;
5
use Ubiquity\security\acl\models\Permission;
6
use Ubiquity\security\acl\models\Resource;
7
use Ubiquity\security\acl\models\Role;
8
9
/**
10
 * Ubiquity\security\acl\persistence$AclArrayProvider
11
 * This class is part of Ubiquity
12
 *
13
 * @author jc
14
 * @version 1.0.0
15
 *
16
 */
17
abstract class AclArrayProvider implements AclProviderInterface {
18
19
	protected $aclsArray;
20
21
	protected $parts;
22
23
	public function __construct() {}
24
25 3
	protected function loadAllPart($class): array {
26 3
		$elements = [];
27 3
		foreach ($this->parts[$class] as $partArray) {
28 3
			$elm = new $class();
29 3
			$elm->fromArray($partArray);
30 3
			$elements[$partArray['name']] = $elm;
31
		}
32 3
		return $elements;
33
	}
34
35
	/**
36
	 *
37
	 * {@inheritdoc}
38
	 * @see \Ubiquity\security\acl\persistence\AclProviderInterface::loadAllAcls()
39
	 */
40 3
	public function loadAllAcls(): array {
41 3
		$acls = [];
42 3
		foreach ($this->aclsArray as $aclArray) {
43 3
			$aclElement = new AclElement();
44 3
			$aclElement->fromArray($aclArray);
45 3
			$acls[$aclElement->getId_()] = $aclElement;
46
		}
47 3
		return $acls;
48
	}
49
50 1
	protected function _saveAcl(AclElement $aclElement) {
51 1
		$this->aclsArray[$aclElement->getId_()] = $aclElement->toArray();
52 1
	}
53
54
	/**
55
	 *
56
	 * {@inheritdoc}
57
	 * @see \Ubiquity\security\acl\persistence\AclProviderInterface::loadAllPermissions()
58
	 */
59 3
	public function loadAllPermissions(): array {
60 3
		return $this->loadAllPart(Permission::class);
61
	}
62
63
	/**
64
	 *
65
	 * {@inheritdoc}
66
	 * @see \Ubiquity\security\acl\persistence\AclProviderInterface::loadAllResources()
67
	 */
68 3
	public function loadAllResources(): array {
69 3
		return $this->loadAllPart(Resource::class);
70
	}
71
72
	/**
73
	 *
74
	 * {@inheritdoc}
75
	 * @see \Ubiquity\security\acl\persistence\AclProviderInterface::loadAllRoles()
76
	 */
77 3
	public function loadAllRoles(): array {
78 3
		return $this->loadAllPart(Role::class);
79
	}
80
81 2
	protected function _savePart(\Ubiquity\security\acl\models\AbstractAclPart $part) {
82 2
		$class = \get_class($part);
83 2
		$this->parts[$class][$part->getName()] = $part->toArray();
84 2
	}
85
}
86
87