Code Duplication    Length = 46-46 lines in 2 locations

core/domain/services/graphql/mutators/EventUpdate.php 1 location

@@ 13-58 (lines=46) @@
10
use WPGraphQL\AppContext;
11
use GraphQL\Error\UserError;
12
13
class EventUpdate {
14
15
	/**
16
	 * Defines the mutation data modification closure.
17
	 *
18
     * @param EEM_Event $model
19
     * @param Event $type
20
	 * @return callable
21
	 */
22
	public static function mutateFields(EEM_Event $model, Event $type)
23
	{
24
		/**
25
		 * Update additional data related to the entity.
26
		 *
27
		 * @param int           $id                   The ID of the postObject being mutated
28
		 * @param array         $input                The input for the mutation
29
		 * @param WP_Post_Type  $post_type_object     The Post Type Object for the type of post being mutated
30
		 * @param string        $mutation_name        The name of the mutation (ex: create, update, delete)
31
		 * @param AppContext    $context              The AppContext passed down to all resolvers
32
		 * @param ResolveInfo   $info                 The ResolveInfo passed down to all resolvers
33
		 */
34
		return static function (
35
			$id,
36
			array $input,
37
			WP_Post_Type $post_type_object,
38
			$mutation_name,
39
			AppContext $context,
40
			ResolveInfo $info
41
		) use ($model, $type)
42
		{
43
			// Make sure we are dealing with the right entity.
44
			if ($post_type_object->graphql_single_name !== $type->name()) {
45
				return;
46
			}
47
48
			$entity = $model->get_one_by_ID($id);
49
50
			if ($entity instanceof EE_Event) {
51
				$args = EventMutation::prepare_fields($input, $mutation_name);
52
	
53
				// Update the entity
54
				$entity->save($args);
55
			}
56
		};
57
	}
58
}
59

core/domain/services/graphql/mutators/VenueUpdate.php 1 location

@@ 13-58 (lines=46) @@
10
use WPGraphQL\AppContext;
11
use GraphQL\Error\UserError;
12
13
class VenueUpdate {
14
15
	/**
16
	 * Defines the mutation data modification closure.
17
	 *
18
     * @param EEM_Venue $model
19
     * @param Venue $type
20
	 * @return callable
21
	 */
22
	public static function mutateFields(EEM_Venue $model, Venue $type)
23
	{
24
		/**
25
		 * Update additional data related to the entity.
26
		 *
27
		 * @param int           $post_id              The ID of the postObject being mutated
28
		 * @param array         $input                The input for the mutation
29
		 * @param WP_Post_Type  $post_type_object     The Post Type Object for the type of post being mutated
30
		 * @param string        $mutation_name        The name of the mutation (ex: create, update, delete)
31
		 * @param AppContext    $context              The AppContext passed down to all resolvers
32
		 * @param ResolveInfo   $info                 The ResolveInfo passed down to all resolvers
33
		 */
34
		return static function (
35
			$post_id,
36
			array $input,
37
			WP_Post_Type $post_type_object,
38
			$mutation_name,
39
			AppContext $context,
40
			ResolveInfo $info
41
		) use ($model, $type)
42
		{
43
			// Make sure we are dealing with the right entity.
44
			if ($post_type_object->graphql_single_name !== $type->name()) {
45
				return;
46
			}
47
48
			$entity = $model->get_one_by_ID($id);
49
50
			if ($entity instanceof EE_Venue) {
51
				$args = VenueMutation::prepare_fields($input, $mutation_name);
52
	
53
				// Update the entity
54
				$entity->save($args);
55
			}
56
		};
57
	}
58
}
59