Test Failed
Push — main ( 573841...5a0b4f )
by Jean-Christophe
06:17
created

AllowAnnotation::initAnnotation()   B

Complexity

Conditions 7
Paths 8

Size

Total Lines 22
Code Lines 17

Duplication

Lines 0
Ratio 0 %

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
rs 8.8333
1
<?php
2
namespace Ubiquity\annotations\acl;
3
4
use Ubiquity\annotations\BaseAnnotation;
0 ignored issues
show
Bug introduced by
The type Ubiquity\annotations\BaseAnnotation was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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
	public function initAnnotation(array $properties) {
30
		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
		} else if (isset($properties['role'])) {
42
			$this->role = $properties['role'];
43
			if (isset($properties['resource'])) {
44
				$this->resource = $properties['resource'];
45
			}
46
			if (isset($properties['permission'])) {
47
				$this->permission = $properties['permission'];
48
			}
49
		} else {
50
			throw new \Exception('Allow annotation must have a role');
51
		}
52
	}
53
}
54