Conditions | 6 |
Paths | 1 |
Total Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
23 | public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type) |
||
24 | { |
||
25 | /** |
||
26 | * Updates 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 | /** @var EE_Ticket $entity */ |
||
36 | $entity = EntityMutator::getEntityFromInputData($model, $input); |
||
37 | |||
38 | $datetimes = []; |
||
39 | $prices = []; |
||
40 | |||
41 | $args = TicketMutation::prepareFields($input); |
||
42 | |||
43 | if (isset($args['datetimes'])) { |
||
44 | $datetimes = $args['datetimes']; |
||
45 | unset($args['datetimes']); |
||
46 | } |
||
47 | if (isset($args['prices'])) { |
||
48 | $prices = $args['prices']; |
||
49 | unset($args['prices']); |
||
50 | } |
||
51 | |||
52 | $entity->save($args); |
||
53 | |||
54 | if (! empty($datetimes)) { |
||
55 | TicketMutation::setRelatedDatetimes($entity, $datetimes); |
||
56 | } |
||
57 | if (! empty($prices)) { |
||
58 | TicketMutation::setRelatedPrices($entity, $prices); |
||
59 | } |
||
60 | } catch (Exception $exception) { |
||
61 | EntityMutator::handleExceptions( |
||
62 | $exception, |
||
63 | esc_html__( |
||
64 | 'The ticket could not be deleted because of the following error(s)', |
||
65 | 'event_espresso' |
||
66 | ) |
||
67 | ); |
||
68 | } |
||
69 | |||
70 | return [ |
||
71 | 'id' => $entity->ID(), |
||
72 | ]; |
||
73 | }; |
||
74 | } |
||
75 | } |
||
76 |