Completed
Branch BETA-4.9-messages-queue-fixed (941081)
by
unknown
17:38 queued 10s
created

Read   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 12 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle_request() 3 18 2

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
namespace EventEspresso\core\libraries\rest_api\controllers\config;
3
if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
4
	exit( 'No direct script access allowed' );
5
}
6
7
/**
8
 *
9
 * _Read
10
 *
11
 * For handling READ requests for config data
12
 *
13
 * @package			Event Espresso
14
 * @subpackage
15
 * @author				Mike Nelson
16
 *
17
 */
18
class Read {
19
20
	/**
21
	 * @param \WP_REST_Request $request
22
	 * @return \EE_Config|\WP_Error
23
	 */
24
	public static function handle_request( \WP_REST_Request $request) {
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
25
		$cap = \EE_Restriction_Generator_Base::get_default_restrictions_cap();
26
		if( \EE_Capabilities::instance()->current_user_can( $cap, 'read_over_api' ) ){
27
			return \EE_Config::instance();
28 View Code Duplication
		}else{
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
			return new \WP_Error(
30
				'cannot_read_config',
31
				sprintf(
32
					__(
33
						'You do not have the necessary capabilities (%s) to read Event Espresso Configuration data',
34
						'event_espresso'
35
					),
36
					$cap
37
				),
38
				array( 'status' => 403 )
39
			);
40
		}
41
	}
42
}
43
44
// End of file Read.php