Completed
Push — try/capabilities ( 1eedd1...45f305 )
by
unknown
06:43
created

AtLeastOneRule::check()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
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 AtLeastOneRule extends AggregateRule {
13
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
14
	public function check( ...$args ) {
15
		foreach ( $this->rules as $rule ) {
16
			$permission = $rule->check();
17
			if ( $permission->granted() ) {
18
				return $permission;
19
			}
20
		}
21
		// TODO: this should be an aggregate permission with all the permission denied reasons available.
22
		return new PermissionDenied( __( 'All aggregate checks failed', 'jetpack' ) );
23
	}
24
}
25