Completed
Branch FET/reg-form-builder/main (a66e69)
by
unknown
09:49 queued 19s
created

FormSectionDelete   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 48
loc 48
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A mutateAndGetPayload() 38 38 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
3
namespace EventEspresso\core\domain\services\graphql\mutators;
4
5
use EE_Form_Section;
6
use EEM_Form_Section;
7
use Exception;
8
use GraphQL\Type\Definition\ResolveInfo;
9
use WPGraphQL\AppContext;
10
11 View Code Duplication
class FormSectionDelete extends EntityMutator
12
{
13
14
    /**
15
     * Defines the mutation data modification closure.
16
     *
17
     * @param EEM_Form_Section $model
18
     * @return callable
19
     */
20
    public static function mutateAndGetPayload(EEM_Form_Section $model)
21
    {
22
        /**
23
         * Deletes an entity.
24
         *
25
         * @param array       $input   The input for the mutation
26
         * @param AppContext  $context The AppContext passed down to all resolvers
27
         * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
28
         * @return array
29
         */
30
        return static function (array $input, AppContext $context, ResolveInfo $info) use ($model): array {
31
            try {
32
                /** @var EE_Form_Section $entity */
33
                $entity = EntityMutator::getEntityFromInputData($model, $input);
34
35
                $result = $entity->delete();
36
                EntityMutator::validateResults($result);
37
38
                do_action(
39
                    'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_section_delete',
40
                    $entity,
41
                    $input
42
                );
43
            } catch (Exception $exception) {
44
                EntityMutator::handleExceptions(
45
                    $exception,
46
                    esc_html__(
47
                        'The form section could not be deleted because of the following error(s)',
48
                        'event_espresso'
49
                    )
50
                );
51
            }
52
53
            return [
54
                'deleted' => $entity,
55
            ];
56
        };
57
    }
58
}
59