Passed
Push — main ( 610fba...dd0d39 )
by Jean-Christophe
02:42
created

AllowAnnotation   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 47.06%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 33
ccs 8
cts 17
cp 0.4706
rs 10
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B initAnnotation() 0 22 7
1
<?php
2
namespace Ubiquity\annotations\acl;
3
4
use Ubiquity\annotations\BaseAnnotation;
5
6
/**
7
 * Annotation Allow.
8
 * usages :
9
 * - allow("roleName")
10
 * - allow("role"=>"roleName")
11
 * - allow("role"=>"roleName","resource"=>"resourceName","permission"=>"permissionName")
12
 * - allow("roleName","resourceName","permissionName")
13
 *
14
 * @author jc
15
 * @version 1.0.0
16
 * @usage('method'=>true,'class'=>true,'inherited'=>true,'multiple'=>true)
17
 */
18
class AllowAnnotation extends BaseAnnotation {
19
20
	public $role;
21
22
	public $permission;
23
24
	public $resource;
25
26
	/**
27
	 * Initialize the annotation.
28
	 */
29 1
	public function initAnnotation(array $properties) {
30 1
		if (isset($properties[0])) {
31
			$this->role = $properties[0];
32
			unset($properties[0]);
33
			if (isset($properties[1])) {
34
				$this->resource = $properties[1];
35
				unset($properties[1]);
36
				if (isset($properties[2])) {
37
					$this->permission = $properties[2];
38
					unset($properties[2]);
39
				}
40
			}
41 1
		} else if (isset($properties['role'])) {
42 1
			$this->role = $properties['role'];
43 1
			if (isset($properties['resource'])) {
44 1
				$this->resource = $properties['resource'];
45
			}
46 1
			if (isset($properties['permission'])) {
47 1
				$this->permission = $properties['permission'];
48
			}
49
		} else {
50
			throw new \Exception('Allow annotation must have a role');
51
		}
52 1
	}
53
}
54