Code Duplication    Length = 3-4 lines in 4 locations

json-endpoints/class.wpcom-json-api-publicize-endpoint.php 3 locations

@@ 7-9 (lines=3) @@
4
	// /sites/%s/connections
5
	function callback( $path = '', $blog_id = 0 ) {
6
		// Verify required Publicize Jetpack module is active
7
		if ( ! class_exists( 'Publicize' ) || ( method_exists( 'Jetpack', 'is_module_active' ) && ! Jetpack::is_module_active( 'publicize' ) ) ) {
8
			return new WP_Error( 'missing_jetpack_module', 'The Publicize module must be activated in order to use this endpoint.', 400 );
9
		}
10
11
		// Authenticate user
12
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ), false );
@@ 99-101 (lines=3) @@
96
	// /sites/%s/connections/$connection_id
97
	function callback( $path = '', $blog_id = 0, $connection_id = 0 ) {
98
		// Verify required Publicize Jetpack module is active
99
		if ( ! class_exists( 'Publicize' ) || ( method_exists( 'Jetpack', 'is_module_active' ) && ! Jetpack::is_module_active( 'publicize' ) ) ) {
100
			return new WP_Error( 'missing_jetpack_module', 'The Publicize module must be activated in order to use this endpoint.', 400 );
101
		}
102
103
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ), false );
104
		if ( is_wp_error( $blog_id ) ) {
@@ 133-135 (lines=3) @@
130
	// /sites/%s/connections/$connection_id/delete
131
	function callback( $path = '', $blog_id = 0 , $connection_id = 0 ) {
132
		// Verify required Publicize Jetpack module is active
133
		if ( ! class_exists( 'Publicize' ) || ( method_exists( 'Jetpack', 'is_module_active' ) && ! Jetpack::is_module_active( 'publicize' ) ) ) {
134
			return new WP_Error( 'missing_jetpack_module', 'The Publicize module must be activated in order to use this endpoint.', 400 );
135
		}
136
137
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $blog_id ), false );
138
		if ( is_wp_error( $blog_id ) ) {

json-endpoints/class.wpcom-json-api-sharing-buttons-endpoint.php 1 location

@@ 14-17 (lines=4) @@
11
12
		if ( ! current_user_can( 'manage_options' ) ) {
13
			return new WP_Error( 'forbidden', 'You do not have the capability to manage sharing buttons for this site', 403 );
14
		} else if ( ! class_exists( 'Sharing_Service' ) || ! class_exists( 'Sharing_Source' ) ||
15
				( method_exists( 'Jetpack', 'is_module_active' ) && ! Jetpack::is_module_active( 'sharedaddy' ) ) ) {
16
			return new WP_Error( 'missing_jetpack_module', 'The Sharing module must be activated in order to use this endpoint', 400 );
17
		}
18
	}
19
20
	public function format_sharing_button( $button ) {