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

JetpackPlanSupportsRule::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 3
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 3
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * A rule which checks whether this site has a Jetpack plan with the given slug
4
 *
5
 * @package automattic/jetpack-capabilities
6
 */
7
8
namespace Automattic\Jetpack\Capabilities;
9
10
// phpcs:ignore Squiz.Commenting.ClassComment.Missing
11 View Code Duplication
class JetpackPlanSupportsRule implements Rule {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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