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

Jetpack_Constants_Sync   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 10
c 2
b 0
f 1
lcom 1
cbo 1
dl 0
loc 62
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A sync() 0 12 2
A sync_all() 0 3 1
A getCheckSum() 0 3 1
A getQueryString() 0 3 1
A constant_values() 0 11 3
A getConstant() 0 7 2
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