Completed
Branch EDTR/master (5c5ec9)
by
unknown
18:46 queued 09:35
created

TicketDelete   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 44
loc 44
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A mutateAndGetPayload() 33 33 3

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
3
namespace EventEspresso\core\domain\services\graphql\mutators;
4
5
use EE_Ticket;
6
use EEM_Ticket;
7
use EventEspresso\core\domain\services\graphql\types\Ticket;
8
use Exception;
9
use GraphQL\Type\Definition\ResolveInfo;
10
use WPGraphQL\AppContext;
11
12 View Code Duplication
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