Passed
Push — main ( a91ba6...0cc46e )
by Jean-Christophe
02:32
created

PermissionAnnotation::initAnnotation()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 15
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5.1158

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 12
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 15
ccs 10
cts 12
cp 0.8333
crap 5.1158
rs 9.5555
1
<?php
2
namespace Ubiquity\annotations\acl;
3
4
use Ubiquity\annotations\BaseAnnotation;
5
6
/**
7
 * Annotation Permission.
8
 * usages :
9
 * - permission("permissionName")
10
 * - permission("permissionName","permissionLevel")
11
 * - permission("name"=>"permissionName")
12
 * - permission("name"=>"permissionName","level"=>"permissionLevel")
13
 *
14
 * @author jc
15
 * @version 1.0.0
16
 * @usage('method'=>true,'class'=>true,'inherited'=>true,'multiple'=>false)
17
 */
18
class PermissionAnnotation extends BaseAnnotation {
19
20
	public $name;
21
22
	public $level;
23
24
	/**
25
	 * Initialize the annotation.
26
	 */
27 1
	public function initAnnotation(array $properties) {
28 1
		if (isset($properties[0])) {
29 1
			$this->name = $properties[0];
30 1
			unset($properties[0]);
31 1
			if (isset($properties[1])) {
32
				$this->level = $properties[1];
33 1
				unset($properties[1]);
34
			}
35 1
		} else if (isset($properties['name'])) {
36 1
			$this->name = $properties['name'];
37 1
			if (isset($properties['level'])) {
38 1
				$this->level = $properties['level'];
39
			}
40
		} else {
41
			throw new \Exception('Permission annotation must have a name');
42
		}
43 1
	}
44
}
45