| Conditions | 4 |
| Paths | 1 |
| Total Lines | 44 |
| Lines | 44 |
| Ratio | 100 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 23 | View Code Duplication | public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
|
| 24 | { |
||
| 25 | /** |
||
| 26 | * Creates 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 | EntityMutator::checkPermissions($model); |
||
| 36 | |||
| 37 | $tickets = []; |
||
| 38 | $args = DatetimeMutation::prepareFields($input); |
||
| 39 | |||
| 40 | if (isset($args['tickets'])) { |
||
| 41 | $tickets = $args['tickets']; |
||
| 42 | unset($args['tickets']); |
||
| 43 | } |
||
| 44 | |||
| 45 | $entity = EE_Datetime::new_instance($args); |
||
| 46 | $id = $entity->save(); |
||
| 47 | EntityMutator::validateResults($id); |
||
| 48 | |||
| 49 | if (! empty($tickets)) { |
||
| 50 | DatetimeMutation::setRelatedTickets($entity, $tickets); |
||
| 51 | } |
||
| 52 | } catch (Exception $exception) { |
||
| 53 | EntityMutator::handleExceptions( |
||
| 54 | $exception, |
||
| 55 | esc_html__( |
||
| 56 | 'The datetime could not be created because of the following error(s)', |
||
| 57 | 'event_espresso' |
||
| 58 | ) |
||
| 59 | ); |
||
| 60 | } |
||
| 61 | |||
| 62 | return [ |
||
| 63 | 'id' => $id, |
||
| 64 | ]; |
||
| 65 | }; |
||
| 66 | } |
||
| 67 | } |
||
| 68 |