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

FormSectionCreate   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A mutateAndGetPayload() 0 41 2
1
<?php
2
3
namespace EventEspresso\core\domain\services\graphql\mutators;
4
5
use EE_Form_Section;
6
use EEM_Form_Section;
7
use EventEspresso\core\domain\services\graphql\types\FormSection;
8
use EventEspresso\core\domain\services\graphql\data\mutations\FormSectionMutation;
9
use GraphQL\Type\Definition\ResolveInfo;
10
use WPGraphQL\AppContext;
11
use Exception;
12
13
class FormSectionCreate extends EntityMutator
14
{
15
16
    /**
17
     * Defines the mutation data modification closure.
18
     *
19
     * @param EEM_Form_Section $model
20
     * @return callable
21
     */
22
    public static function mutateAndGetPayload(EEM_Form_Section $model)
23
    {
24
        /**
25
         * Creates 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 (array $input, AppContext $context, ResolveInfo $info) use ($model): array {
33
            $id = null;
34
            try {
35
                EntityMutator::checkPermissions($model);
36
37
                $args = FormSectionMutation::prepareFields($input);
38
39
                $entity = EE_Form_Section::new_instance($args);
40
                $id = $entity->save();
41
                EntityMutator::validateResults($id);
42
43
                do_action(
44
                    'AHEE__EventEspresso_core_domain_services_graphql_mutators_form_section_create',
45
                    $entity,
46
                    $input
47
                );
48
            } catch (Exception $exception) {
49
                EntityMutator::handleExceptions(
50
                    $exception,
51
                    esc_html__(
52
                        'The form section could not be created because of the following error(s)',
53
                        'event_espresso'
54
                    )
55
                );
56
            }
57
58
            return [
59
                'id' => $id,
60
            ];
61
        };
62
    }
63
}
64