Code Duplication    Length = 25-26 lines in 2 locations

packages/capabilities/src/Capabilities/class-jetpackplanrule.php 1 location

@@ 11-36 (lines=26) @@
8
namespace Automattic\Jetpack\Capabilities;
9
10
// phpcs:ignore Squiz.Commenting.ClassComment.Missing
11
class JetpackPlanRule implements Rule {
12
	/**
13
	 * The _minimum_ required Jetpack plan slug
14
	 *
15
	 * @var string plan_slug
16
	 */
17
	private $plan_slug;
18
19
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
20
	public function __construct( $plan_slug ) {
21
		$this->plan_slug = $plan_slug;
22
	}
23
24
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
25
	public function check( ...$args ) {
26
		$plan = \Jetpack_Plan::get();
27
		if ( $this->plan_slug === $plan['product_slug'] ) {
28
			return new PermissionGranted();
29
		} else {
30
			return new PermissionDenied(
31
				// translators: Argument is a Jetpack plan slug, e.g. jetpack_premium.
32
				sprintf( __( 'You must have plan %s to perform this action', 'jetpack' ), $this->plan_slug )
33
			);
34
		}
35
	}
36
}
37

packages/capabilities/src/Capabilities/class-jetpackplansupportsrule.php 1 location

@@ 11-35 (lines=25) @@
8
namespace Automattic\Jetpack\Capabilities;
9
10
// phpcs:ignore Squiz.Commenting.ClassComment.Missing
11
class JetpackPlanSupportsRule implements Rule {
12
	/**
13
	 * The feature that the current Jetpack plan must support
14
	 *
15
	 * @var string supports_slug
16
	 */
17
	private $supports_slug;
18
19
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
20
	public function __construct( $supports_slug ) {
21
		$this->supports_slug = $supports_slug;
22
	}
23
24
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
25
	public function check( ...$args ) {
26
		if ( \Jetpack_Plan::supports( $this->supports_slug ) ) {
27
			return new PermissionGranted();
28
		} else {
29
			return new PermissionDenied(
30
				// translators: Argument is a Jetpack plan slug, e.g. jetpack_premium.
31
				sprintf( __( 'You must have plan %s to perform this action', 'jetpack' ), $this->supports_slug )
32
			);
33
		}
34
	}
35
}
36