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

AllowAnnotation::initAnnotation()   B

Complexity

Conditions 7
Paths 8

Size

Total Lines 22
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 14.2702

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 17
c 1
b 0
f 0
nc 8
nop 1
dl 0
loc 22
ccs 8
cts 17
cp 0.4706
crap 14.2702
rs 8.8333
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