Passed
Push — main ( 5080f0...5604a8 )
by Jean-Christophe
02:26
created

AclControllerTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 7 2
1
<?php
2
namespace Ubiquity\security\acl\controllers;
3
4
use Ubiquity\security\acl\AclManager;
5
6
/**
7
 * To use with a controller with acls.
8
 * Ubiquity\security\acl\controllers$AclControllerTrait
9
 * This class is part of Ubiquity
10
 *
11
 * @author jc
12
 * @version 1.0.0
13
 *
14
 */
15
trait AclControllerTrait {
16
17
	public abstract function _getRole();
18
19
	/**
20
	 * Returns True if access to the controller is allowed for the role returned by _getRole method.
21
	 * To be override in sub classes
22
	 *
23
	 * @param string $action
24
	 * @return boolean
25
	 */
26 1
	public function isValid($action) {
27 1
		$controller = \get_class($this);
28 1
		$resourceController = AclManager::getPermissionMap()->getRessourcePermission($controller, $action);
29 1
		if (isset($resourceController)) {
30 1
			return AclManager::isAllowed($this->_getRole(), $resourceController['resource'], $resourceController['permission']);
31
		}
32 1
		return true;
33
	}
34
}
35
36