Completed
Push — update/connection-package-xmlr... ( ca82eb )
by
unknown
20:02
created

Jetpack_XMLRPC_Methods   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 29.03 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 18
loc 62
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
A xmlrpc_methods() 0 7 1
A features_available() 9 9 2
A features_enabled() 9 9 2
A test_connection() 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
 * Jetpack XMLRPC Methods.
4
 *
5
 * Registers the Jetpack specific XMLRPC methods
6
 *
7
 * @package jetpack
8
 */
9
10
/**
11
 * XMLRPC Methods registration and callbacks
12
 */
13
class Jetpack_XMLRPC_Methods {
14
15
	/**
16
	 * Initialize the main hooks.
17
	 */
18
	public static function init() {
19
		add_filter( 'jetpack_xmlrpc_unauthenticated_methods', array( __CLASS__, 'xmlrpc_methods' ) );
20
		add_filter( 'jetpack_xmlrpc_test_connection_response', array( __CLASS__, 'test_connection' ) );
21
	}
22
23
	/**
24
	 * Adds Jetpack specific methods to the methods added by the Connection package.
25
	 *
26
	 * @param array $methods Methods added by the Connection package.
27
	 */
28
	public function xmlrpc_methods( $methods ) {
29
30
		$methods['jetpack.featuresAvailable'] = array( __CLASS__, 'features_available' );
31
		$methods['jetpack.featuresEnabled']   = array( __CLASS__, 'features_enabled' );
32
33
		return $methods;
34
	}
35
36
	/**
37
	 * Returns what features are available. Uses the slug of the module files.
38
	 *
39
	 * @return array
40
	 */
41 View Code Duplication
	public static function features_available() {
42
		$raw_modules = Jetpack::get_available_modules();
43
		$modules     = array();
44
		foreach ( $raw_modules as $module ) {
45
			$modules[] = Jetpack::get_module_slug( $module );
46
		}
47
48
		return $modules;
49
	}
50
51
	/**
52
	 * Returns what features are enabled. Uses the slug of the modules files.
53
	 *
54
	 * @return array
55
	 */
56 View Code Duplication
	public static function features_enabled() {
57
		$raw_modules = Jetpack::get_active_modules();
58
		$modules     = array();
59
		foreach ( $raw_modules as $module ) {
60
			$modules[] = Jetpack::get_module_slug( $module );
61
		}
62
63
		return $modules;
64
	}
65
66
	/**
67
	 * Filters the result of test_connection XMLRPC method
68
	 *
69
	 * @return string The current Jetpack version number
70
	 */
71
	public function test_connection() {
72
		return JETPACK__VERSION;
73
	}
74
}
75