Conditions | 6 |
Paths | 1 |
Total Lines | 37 |
Lines | 4 |
Ratio | 10.81 % |
Changes | 0 |
1 | <?php |
||
21 | public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type) |
||
22 | { |
||
23 | return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) |
||
24 | { |
||
25 | /** |
||
26 | * Stop now if a user isn't allowed to create a datetime. |
||
27 | */ |
||
28 | View Code Duplication | if (! current_user_can('ee_edit_events')) { |
|
29 | // translators: the %1$s is the name of the object being mutated |
||
30 | throw new UserError(sprintf(__('Sorry, you are not allowed to edit %1$s', 'event_espresso' ), $type->name())); |
||
31 | } |
||
32 | |||
33 | $id = ! empty($input['id']) ? absint($input['id']) : 0; |
||
34 | $entity = null; |
||
35 | |||
36 | if ($id) { |
||
37 | $entity = $model->get_one_by_ID($id); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * If there's no existing datetime, throw an exception |
||
42 | */ |
||
43 | if (! $id || ! ($entity instanceof EE_Datetime)) { |
||
44 | // translators: the placeholder is the name of the type being updated |
||
45 | throw new UserError(sprintf(__( 'No %1$s could be found to update', 'event_espresso' ), $type->name())); |
||
46 | } |
||
47 | |||
48 | $args = DatetimeMutation::prepare_fields($input, $mutation_name); |
||
|
|||
49 | |||
50 | // Update the entity |
||
51 | $entity->save($args); |
||
52 | |||
53 | return [ |
||
54 | 'id' => $id, |
||
55 | ]; |
||
56 | }; |
||
57 | } |
||
58 | } |
||
59 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.