Completed
Push — try/capabilities ( 672273...ec87c0 )
by
unknown
15:57 queued 09:35
created

Builder::create()   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( $name ) {
23
		$this->capability = new Capability( $name );
24
		return $this;
25
	}
26
27
	/**
28
	 * Register a capability globally
29
	 */
30
	public function register() {
31
		$this->capability->register();
32
		return $this;
33
	}
34
35
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
36
	public function get() {
37
		return $this->capability;
38
	}
39
40
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
41
	public function add_rule( Rule $rule ) {
42
		$this->capability->add_rule( $rule );
43
		return $this;
44
	}
45
46
	/**
47
	 * The following functions are basically just shortcuts to the above ->add_rule method
48
	 */
49
50
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
51
	public function require_wp_role( $wp_role ) {
52
		return $this->add_rule( new WPRoleRule( $wp_role ) );
53
	}
54
55
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
56
	public function require_wp_capability( $wp_capability ) {
57
		return $this->add_rule( new WPCapabilityRule( $wp_capability ) );
58
	}
59
60
	/**
61
	 * For traditional Jetpack plans (free, personal, premium, professional ) this
62
	 * specifies the minimum plan required in required to perform the action
63
	 *
64
	 * @param string $jetpack_plan_level The Jetpack plan level.
65
	 */
66
	public function require_minimum_jetpack_plan( $jetpack_plan_level ) {
67
		return $this->add_rule( new JetpackPlanRule( $jetpack_plan_level ) );
68
	}
69
}
70