Code Duplication    Length = 43-45 lines in 4 locations

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

@@ 12-55 (lines=44) @@
9
use GraphQL\Type\Definition\ResolveInfo;
10
use WPGraphQL\AppContext;
11
12
class DatetimeDelete extends EntityMutator
13
{
14
15
    /**
16
     * Defines the mutation data modification closure.
17
     *
18
     * @param EEM_Datetime $model
19
     * @param Datetime     $type
20
     * @return callable
21
     */
22
    public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type)
23
    {
24
        /**
25
         * Deletes an entity.
26
         *
27
         * @param array       $input   The input for the mutation
28
         * @param AppContext  $context The AppContext passed down to all resolvers
29
         * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
30
         * @return array|void
31
         */
32
        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
33
            try {
34
                /** @var EE_Datetime $entity */
35
                $entity = EntityMutator::getEntityFromInputData($model, $input);
36
37
                // Delete the entity
38
                $result = ! empty($input['deletePermanently']) ? $entity->delete_permanently() : $entity->delete();
39
                EntityMutator::validateResults($result);
40
            } catch (Exception $exception) {
41
                EntityMutator::handleExceptions(
42
                    $exception,
43
                    esc_html__(
44
                        'The datetime could not be deleted because of the following error(s)',
45
                        'event_espresso'
46
                    )
47
                );
48
            }
49
50
            return [
51
                'deleted' => $entity,
52
            ];
53
        };
54
    }
55
}
56

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

@@ 12-54 (lines=43) @@
9
use GraphQL\Type\Definition\ResolveInfo;
10
use WPGraphQL\AppContext;
11
12
class PriceDelete extends EntityMutator
13
{
14
15
    /**
16
     * Defines the mutation data modification closure.
17
     *
18
     * @param EEM_Price $model
19
     * @param Price     $type
20
     * @return callable
21
     */
22
    public static function mutateAndGetPayload(EEM_Price $model, Price $type)
23
    {
24
        /**
25
         * Deletes an entity.
26
         *
27
         * @param array       $input   The input for the mutation
28
         * @param AppContext  $context The AppContext passed down to all resolvers
29
         * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
30
         * @return array
31
         */
32
        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
33
            try {
34
                /** @var EE_Price $entity */
35
                $entity = EntityMutator::getEntityFromInputData($model, $input);
36
                // Delete the entity
37
                $result = ! empty($input['deletePermanently']) ? $entity->delete_permanently() : $entity->delete();
38
                EntityMutator::validateResults($result);
39
            } catch (Exception $exception) {
40
                EntityMutator::handleExceptions(
41
                    $exception,
42
                    esc_html__(
43
                        'The price could not be deleted because of the following error(s)',
44
                        'event_espresso'
45
                    )
46
                );
47
            }
48
49
            return [
50
                'deleted' => $entity,
51
            ];
52
        };
53
    }
54
}
55

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

@@ 13-57 (lines=45) @@
10
use GraphQL\Type\Definition\ResolveInfo;
11
use WPGraphQL\AppContext;
12
13
class PriceUpdate extends EntityMutator
14
{
15
16
    /**
17
     * Defines the mutation data modification closure.
18
     *
19
     * @param EEM_Price $model
20
     * @param Price     $type
21
     * @return callable
22
     */
23
    public static function mutateAndGetPayload(EEM_Price $model, Price $type)
24
    {
25
        /**
26
         * Updates an entity.
27
         *
28
         * @param array       $input   The input for the mutation
29
         * @param AppContext  $context The AppContext passed down to all resolvers
30
         * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
31
         * @return array
32
         */
33
        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
34
            try {
35
                /** @var EE_Price $entity */
36
                $entity = EntityMutator::getEntityFromInputData($model, $input);
37
38
                $args = PriceMutation::prepareFields($input);
39
40
                // Update the entity
41
                $entity->save($args);
42
            } catch (Exception $exception) {
43
                EntityMutator::handleExceptions(
44
                    $exception,
45
                    esc_html__(
46
                        'The price could not be updated because of the following error(s)',
47
                        'event_espresso'
48
                    )
49
                );
50
            }
51
52
            return [
53
                'id' => $entity->ID(),
54
            ];
55
        };
56
    }
57
}
58

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

@@ 12-55 (lines=44) @@
9
use GraphQL\Type\Definition\ResolveInfo;
10
use WPGraphQL\AppContext;
11
12
class TicketDelete extends EntityMutator
13
{
14
15
    /**
16
     * Defines the mutation data modification closure.
17
     *
18
     * @param EEM_Ticket $model
19
     * @param Ticket     $type
20
     * @return callable
21
     */
22
    public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type)
23
    {
24
        /**
25
         * Deletes an entity.
26
         *
27
         * @param array       $input   The input for the mutation
28
         * @param AppContext  $context The AppContext passed down to all resolvers
29
         * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
30
         * @return array
31
         */
32
        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
33
            try {
34
                /** @var EE_Ticket $entity */
35
                $entity = EntityMutator::getEntityFromInputData($model, $input);
36
37
                // Delete the entity
38
                $result = ! empty($input['deletePermanently']) ? $entity->delete_permanently() : $entity->delete();
39
                EntityMutator::validateResults($result);
40
            } catch (Exception $exception) {
41
                EntityMutator::handleExceptions(
42
                    $exception,
43
                    esc_html__(
44
                        'The ticket could not be deleted because of the following error(s)',
45
                        'event_espresso'
46
                    )
47
                );
48
            }
49
50
            return [
51
                'deleted' => $entity,
52
            ];
53
        };
54
    }
55
}
56