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

Builder::add_rule()   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 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * A class that can be used to build capability objects composed of many rules
4
 *
5
 * @package automattic/jetpack-capabilities
6
 */
7
8
namespace Automattic\Jetpack\Capabilities;
9
10
use \Automattic\Jetpack\Capabilities;
11
12
// phpcs:ignore Squiz.Commenting.ClassComment.Missing
13
class Builder {
14
	/**
15
	 * The capability object under construction
16
	 *
17
	 * @var Capability capability
18
	 */
19
	public $capability;
20
21
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
22
	public function create_capability( $name ) {
23
		$this->capability = new Capability( $name );
24
		return $this;
25
	}
26
27
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
28
	public function get_capability() {
29
		return $this->capability;
30
	}
31
32
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
33
	public function add_rule( Rule $rule ) {
34
		$this->capability->add_rule( $rule );
35
		return $this;
36
	}
37
38
	/**
39
	 * The following functions are basically just shortcuts to the above ->add_rule method
40
	 */
41
42
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
43
	public function require_wp_role( $wp_role ) {
44
		return $this->add_rule( new WPRoleRule( $wp_role ) );
45
	}
46
47
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
48
	public function require_wp_capability( $wp_capability ) {
49
		return $this->add_rule( new WPCapabilityRule( $wp_capability ) );
50
	}
51
52
	/**
53
	 * For traditional Jetpack plans (free, personal, premium, professional ) this
54
	 * specifies the minimum plan required in required to perform the action
55
	 *
56
	 * @param string $jetpack_plan_level The Jetpack plan level.
57
	 */
58
	public function require_minimum_jetpack_plan( $jetpack_plan_level ) {
59
		return $this->add_rule( new JetpackPlanRule( $jetpack_plan_level ) );
60
	}
61
62
	/**
63
	 * Register a capability globally
64
	 */
65
	public function register() {
66
		Capabilities::register( $this->capability );
67
	}
68
}
69