Completed
Push — add/sync-rest-options ( 3a27a6...110de2 )
by
unknown
08:34
created

class.jetpack-sync-functions.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
class Jetpack_Sync_Functions {
4
5
	static $functions = array(
6
		'wp_version' => array( 'Jetpack', 'get_wp_version' ),
7
		'wp_max_upload_size' => 'wp_max_upload_size',
8
		'network_name' => array( 'Jetpack', 'network_name' ),
9
	);
10
11
	static $sync = array();
12
13
	static function sync() {
14
		return self::values( self::get_function_to_sync() );
15
	}
16
17 View Code Duplication
	static function sync_sometimes() {
18
		// Since there are option in the sync we know that things have changed.
19
		if ( ! empty ( self::$sync ) ) {
20
			return self::sync_all();
21
		}
22
23
		$values           = self::values( self::$functions );
24
		$check_sum        = self::get_check_sum( $values );
25
26
		if ( Jetpack_Options::get_option( 'options_check_sum' ) !== $check_sum ) {
27
			return self::sync_all( $values, $check_sum );
28
		}
29
		return array();
30
	}
31
32 View Code Duplication
	static function sync_all( $values = null, $check_sum = null ) {
33
		if ( is_null( $values ) ) {
34
			$values           = self::values( self::$functions );
0 ignored issues
show
Equals sign not aligned correctly; expected 1 space but found 11 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
35
		}
36
		if( is_null( $check_sum ) ) {
37
			$check_sum = self::get_check_sum( $values );
38
		}
39
		Jetpack_Options::update_option( 'function_check_sum', $check_sum );
40
		return $values;
41
	}
42
43
	static function get_check_sum( $values = null ) {
44
		if( is_null( $values ) ){
45
			$values = self::values();
46
		}
47
		return crc32( self::get_query_string( $values ) );
48
	}
49
50
	static function get_query_string( $values ) {
51
		return build_query( $values );
52
	}
53
54 View Code Duplication
	static function values( $sync = array() ) {
55
		$values = array();
56
		if ( ! empty( $sync ) ) {
57
			foreach ( $sync as $key => $function ) {
58
				$values[ $key ] = self::get( $function );
59
			}
60
		}
61
		return $values;
62
	}
63
64
	static function get_function_to_sync() {
65
		return array_unique( self::$sync );
66
	}
67
68
	static function get( $function ) {
69
		return call_user_func( $function );
70
	}
71
72
}
73
74
75
76
77
78