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

PermissionAnnotation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 24
ccs 10
cts 12
cp 0.8333
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A initAnnotation() 0 15 5
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