Completed
Branch EDTR/refactor-fast-api-fetch (d0e0df)
by
unknown
09:08 queued 34s
created

EventMutation   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 34
loc 34
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A prepare_fields() 21 21 4

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\domain\services\graphql\data\mutations;
3
4
use GraphQL\Error\UserError;
5
6
/**
7
 * Class EventMutation
8
 *
9
 * @package       Event Espresso
10
 * @author        Manzoor Wani
11
 */
12 View Code Duplication
class EventMutation
13
{
14
15
	/**
16
	 * Maps the GraphQL input to a format that the model functions can use
17
	 *
18
	 * @param array  $input         Data coming from the GraphQL mutation query input
19
	 * @param string $mutation_name Name of the mutation being performed
20
	 *
21
	 * @return array
22
	 */
23
	public static function prepare_fields(array $input, $mutation_name)
24
	{
25
26
		$args = [];
27
28
		if ( ! empty( $input['name'] ) ) {
29
			$args['EVT_name'] = sanitize_text_field( $input['name'] );
30
		}
31
32
		if ( ! empty( $input['desc'] ) ) {
33
			$args['EVT_desc'] = sanitize_text_field( $input['desc'] );
34
		}
35
36
		if ( ! empty( $input['shortDesc'] ) ) {
37
			$args['EVT_short_desc'] = sanitize_text_field( $input['shortDesc'] );
38
		}
39
40
		// Likewise the other fields...
41
42
		return $args;
43
	}
44
45
}
46