Completed
Push — add/sync-rest-options ( 12319b...b863e4 )
by
unknown
12:29 queued 04:13
created

Jetpack_Constants_Sync::sync_all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
class Jetpack_Constants_Sync {
4
5
	static $constants = array(
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $constants.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
6
		'EMPTY_TRASH_DAYS',
7
		'WP_POST_REVISIONS',
8
		'AUTOMATIC_UPDATER_DISABLED',
9
		'ABSPATH',
10
		'WP_CONTENT_DIR',
11
		'FS_METHOD',
12
		'DISALLOW_FILE_EDIT',
13
		'DISALLOW_FILE_MODS',
14
		'WP_AUTO_UPDATE_CORE',
15
		'WP_HTTP_BLOCK_EXTERNAL',
16
		'WP_ACCESSIBLE_HOSTS',
17
	);
18
19
	static function sync() {
20
		$values           = self::constant_values();
21
		$constantCheckSum = self::getCheckSum( $values );
22
23
		if ( Jetpack_Options::get_option( 'constant_check_sum' ) !== $constantCheckSum ) {
24
			Jetpack_Options::update_option( 'constant_check_sum', $constantCheckSum );
25
26
			return $values;
27
		}
28
29
		return null;
30
	}
31
32
	static function sync_all() {
33
		return self::constant_values();
34
	}
35
36
	static function getCheckSum( $values ) {
37
		return crc32( self::getQueryString( $values ) );
38
	}
39
40
	static function getQueryString( $values ) {
41
		return build_query( $values );
42
	}
43
44
	static function constant_values() {
45
		$constants_values = array();
46
		foreach ( self::$constants as $constant ) {
47
			$value = self::getConstant( $constant );
48
			if ( ! is_null( $value ) ) {
49
				$constants_values[ $constant ] = $value;
50
			}
51
		}
52
53
		return $constants_values;
54
	}
55
56
	static function getConstant( $constant ) {
57
		if ( defined( $constant ) ) {
58
			return constant( $constant );
59
		}
60
61
		return null;
62
	}
63
64
}
65
66
67
68
69
70