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

AggregatePermission::data()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * A permission object that aggregates the output of other permissions
4
 *
5
 * @package automattic/jetpack-capabilities
6
 */
7
8
namespace Automattic\Jetpack\Capabilities;
9
10
// phpcs:ignore Squiz.Commenting.ClassComment.Missing
11
class AggregatePermission implements Permission {
12
	/**
13
	 * The set of permissions that must all be true for aggregate permission to be granted
14
	 *
15
	 * @var array permissions
16
	 */
17
	private $permissions;
18
19
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
20
	public function __construct() {
21
		$this->permissions = [];
22
	}
23
24
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
25
	public function add_permission( $permission ) {
26
		$this->permissions[] = $permission;
27
	}
28
29
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
30
	public function granted() {
31
		foreach ( $this->permissions as $permission ) {
32
			if ( ! $permission->granted() ) {
33
				return false;
34
			}
35
		}
36
		return true;
37
	}
38
39
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
40
	public function message() {
41
		// for now, just return the first message for a negative grant?
42
		foreach ( $this->permissions as $permission ) {
43
			if ( ! $permission->granted() ) {
44
				return $permission->message();
45
			}
46
		}
47
		return null;
48
	}
49
50
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
51
	public function data() {
52
		// TODO: aggregate the data of the permissions.
53
		return null;
54
	}
55
}
56