Completed
Push — master ( 964196...26794c )
by
unknown
18:32 queued 13s
created

WC_WCCOM_Site_Installer_Requirements_Check   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 8.7 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 4
loc 46
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A met_requirements() 4 18 4
A met_wp_cron_requirement() 0 3 2
A met_filesystem_requirement() 0 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * WooCommerce.com Product Installation Requirements Check.
4
 *
5
 * @package WooCommerce\WooCommerce_Site
6
 * @since   3.8.0
7
 */
8
9
defined( 'ABSPATH' ) || exit;
10
11
/**
12
 * WC_WCCOM_Site_Installer_Requirements_Check Class
13
 * Contains functionality to check the necessary requirements for the installer.
14
 */
15
class WC_WCCOM_Site_Installer_Requirements_Check {
16
	/**
17
	 * Check if the site met the requirements
18
	 *
19
	 * @version 3.8.0
20
	 * @return bool|WP_Error Does the site met the requirements?
21
	 */
22
	public static function met_requirements() {
23
		$errs = [];
24
25
		if ( ! self::met_wp_cron_requirement() ) {
26
			$errs[] = 'wp-cron';
27
		}
28
29
		if ( ! self::met_filesystem_requirement() ) {
30
			$errs[] = 'filesystem';
31
		}
32
33 View Code Duplication
		if ( ! empty( $errs ) ) {
34
			// translators: %s: Requirements unmet.
35
			return new WP_Error( 'requirements_not_met', sprintf( __( 'Server requirements not met, missing requirement(s): %s.', 'woocommerce' ), implode( ', ', $errs ) ), array( 'status' => 400 ) );
36
		}
37
38
		return true;
39
	}
40
41
	/**
42
	 * Validates if WP CRON is enabled.
43
	 *
44
	 * @since 3.8.0
45
	 * @return bool
46
	 */
47
	private static function met_wp_cron_requirement() {
48
		return ! ( defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON );
49
	}
50
51
	/**
52
	 * Validates if `WP_CONTENT_DIR` is writable.
53
	 *
54
	 * @since 3.8.0
55
	 * @return bool
56
	 */
57
	private static function met_filesystem_requirement() {
58
		return is_writable( WP_CONTENT_DIR );
59
	}
60
}
61