Completed
Push — try/capabilities ( 7f65a9...672273 )
by
unknown
19:16 queued 12:21
created

Capability   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A add_rule() 0 3 1
A check() 0 7 2
1
<?php
2
/**
3
 * A named rule composed of other rules that represents a high-level user capability, e.g. restoring backups
4
 *
5
 * @package automattic/jetpack-capabilities
6
 */
7
8
namespace Automattic\Jetpack\Capabilities;
9
10
// TODO: should this be called "AggregateRule"?
11
// phpcs:ignore Squiz.Commenting.ClassComment.Missing
12
class Capability implements Rule {
13
	/**
14
	 * The name of the capability, e.g. jetpack.backups.restore
15
	 *
16
	 * @var string name
17
	 */
18
	public $name;
19
20
	/**
21
	 * The set of rules used to evaluate if permission is granted
22
	 *
23
	 * @var array rules
24
	 */
25
	private $rules;
26
27
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
28
	public function __construct( $name ) {
29
		$this->name  = $name;
30
		$this->rules = [];
31
	}
32
33
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
34
	public function add_rule( $rule ) {
35
		$this->rules[] = $rule;
36
	}
37
38
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
39
	public function check( ...$args ) {
40
		$permission = new AggregatePermission();
41
		foreach ( $this->rules as $rule ) {
42
			$permission->add_permission( $rule->check() );
43
		}
44
		return $permission;
45
	}
46
}
47