Completed
Branch EDTR/db-error-messages (933cbd)
by
unknown
09:53 queued 45s
created
core/domain/services/graphql/data/mutations/TicketMutation.php 2 patches
Unused Use Statements   -4 removed lines patch added patch discarded remove patch
@@ -2,7 +2,6 @@  discard block
 block discarded – undo
2 2
 
3 3
 namespace EventEspresso\core\domain\services\graphql\data\mutations;
4 4
 
5
-use DomainException;
6 5
 use EE_Error;
7 6
 use Exception;
8 7
 use GraphQLRelay\Relay;
@@ -12,9 +11,6 @@  discard block
 block discarded – undo
12 11
 use EE_Ticket;
13 12
 use EventEspresso\core\exceptions\InvalidDataTypeException;
14 13
 use EventEspresso\core\exceptions\InvalidInterfaceException;
15
-use EventEspresso\core\exceptions\ModelConfigurationException;
16
-use EventEspresso\core\exceptions\UnexpectedEntityException;
17
-use EventEspresso\core\libraries\rest_api\RestException;
18 14
 use InvalidArgumentException;
19 15
 use ReflectionException;
20 16
 
Please login to merge, or discard this patch.
Indentation   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -27,188 +27,188 @@
 block discarded – undo
27 27
 class TicketMutation
28 28
 {
29 29
 
30
-    /**
31
-     * Maps the GraphQL input to a format that the model functions can use
32
-     *
33
-     * @param array $input Data coming from the GraphQL mutation query input
34
-     * @return array
35
-     * @throws Exception
36
-     */
37
-    public static function prepareFields(array $input)
38
-    {
39
-        $args = [];
40
-
41
-        if (! empty($input['datetimes'])) {
42
-            $args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']);
43
-        }
44
-
45
-        if (! empty($input['description'])) {
46
-            $args['TKT_description'] = sanitize_text_field($input['description']);
47
-        }
48
-
49
-        if (! empty($input['endDate'])) {
50
-            $args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate']));
51
-        }
52
-
53
-        if (array_key_exists('isDefault', $input)) {
54
-            $args['TKT_is_default'] = (bool) $input['isDefault'];
55
-        }
56
-
57
-        if (array_key_exists('isRequired', $input)) {
58
-            $args['TKT_required'] = (bool) $input['isRequired'];
59
-        }
60
-
61
-        if (array_key_exists('isTaxable', $input)) {
62
-            $args['TKT_taxable'] = (bool) $input['isTaxable'];
63
-        }
64
-
65
-        if (array_key_exists('isTrashed', $input)) {
66
-            $args['TKT_deleted'] = (bool) $input['isTrashed'];
67
-        }
68
-
69
-        if (array_key_exists('max', $input)) {
70
-            $args['TKT_max'] = (int) $input['max'];
71
-        }
72
-
73
-        if (array_key_exists('min', $input)) {
74
-            $args['TKT_min'] = (int) $input['min'];
75
-        }
76
-
77
-        if (! empty($input['name'])) {
78
-            $args['TKT_name'] = sanitize_text_field($input['name']);
79
-        }
80
-
81
-        if (array_key_exists('order', $input)) {
82
-            $args['TKT_order'] = (int) $input['order'];
83
-        }
84
-
85
-        if (! empty($input['parent'])) {
86
-            $parts = Relay::fromGlobalId(sanitize_text_field($input['parent']));
87
-            $args['TKT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null;
88
-        }
89
-
90
-        if (! empty($input['price'])) {
91
-            $args['TKT_price'] = (float) $input['price'];
92
-        }
93
-
94
-        if (! empty($input['prices'])) {
95
-            $args['prices'] = array_map('sanitize_text_field', (array) $input['prices']);
96
-        }
97
-
98
-        if (array_key_exists('quantity', $input)) {
99
-            $args['TKT_qty'] = (int) $input['quantity'];
100
-        }
101
-
102
-        if (array_key_exists('reserved', $input)) {
103
-            $args['TKT_reserved'] = (int) $input['reserved'];
104
-        }
105
-
106
-        if (array_key_exists('reverseCalculate', $input)) {
107
-            $args['TKT_reverse_calculate'] = (bool) $input['reverseCalculate'];
108
-        }
109
-
110
-        if (array_key_exists('row', $input)) {
111
-            $args['TKT_row'] = (int) $input['row'];
112
-        }
113
-
114
-        if (array_key_exists('sold', $input)) {
115
-            $args['TKT_sold'] = (int) $input['sold'];
116
-        }
117
-
118
-        if (! empty($input['startDate'])) {
119
-            $args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate']));
120
-        }
121
-
122
-        if (array_key_exists('uses', $input)) {
123
-            $args['TKT_uses'] = (int) $input['uses'];
124
-        }
125
-
126
-        if (! empty($input['wpUser'])) {
127
-            $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser']));
128
-            $args['TKT_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null;
129
-        }
130
-
131
-        return $args;
132
-    }
133
-
134
-
135
-    /**
136
-     * Sets the related datetimes for the given ticket.
137
-     *
138
-     * @param EE_Ticket $entity    The Ticket instance.
139
-     * @param array     $datetimes Array of datetime IDs to relate.
140
-     * @throws EE_Error
141
-     * @throws InvalidArgumentException
142
-     * @throws InvalidDataTypeException
143
-     * @throws InvalidInterfaceException
144
-     * @throws ReflectionException
145
-     */
146
-    public static function setRelatedDatetimes($entity, array $datetimes)
147
-    {
148
-        $relationName = 'Datetime';
149
-        // Remove all the existing related datetimes
150
-
151
-        $entity->_remove_relations($relationName);
152
-        // @todo replace loop with single query
153
-        foreach ($datetimes as $ID) {
154
-            $parts = Relay::fromGlobalId($ID);
155
-            if (! empty($parts['id']) && absint($parts['id'])) {
156
-                $entity->_add_relation_to(
157
-                    $parts['id'],
158
-                    $relationName
159
-                );
160
-            }
161
-        }
162
-    }
163
-
164
-
165
-    /**
166
-     * Sets the related prices for the given ticket.
167
-     *
168
-     * @param EE_Ticket $entity The Ticket instance.
169
-     * @param array     $prices Array of entity IDs to relate.
170
-     * @throws EE_Error
171
-     * @throws InvalidArgumentException
172
-     * @throws InvalidDataTypeException
173
-     * @throws InvalidInterfaceException
174
-     * @throws ReflectionException
175
-     */
176
-    public static function setRelatedPrices($entity, array $prices)
177
-    {
178
-        $relationName = 'Price';
179
-        // Remove all the existing related entities
180
-        $entity->_remove_relations($relationName);
181
-
182
-        // @todo replace loop with single query
183
-        foreach ($prices as $ID) {
184
-            $parts = Relay::fromGlobalId($ID);
185
-            if (! empty($parts['id']) && absint($parts['id'])) {
186
-                $entity->_add_relation_to(
187
-                    $parts['id'],
188
-                    $relationName
189
-                );
190
-            }
191
-        }
192
-    }
193
-
194
-
195
-    /**
196
-     * @param EE_Ticket  $ticket_entity
197
-     * @param EEM_Ticket $ticket_model
198
-     * @throws EE_Error
199
-     * @throws InvalidArgumentException
200
-     * @throws InvalidDataTypeException
201
-     * @throws InvalidInterfaceException
202
-     * @throws ReflectionException
203
-     * @since $VID:$
204
-     */
205
-    public static function addDefaultPrices(EE_Ticket $ticket_entity, EEM_Ticket $ticket_model)
206
-    {
207
-        $price_model = EEM_Price::instance();
208
-        $default_prices = $price_model->get_all_default_prices();
209
-        foreach ($default_prices as $default_price) {
210
-            $default_price->save();
211
-            $default_price->_add_relation_to($ticket_entity, 'Ticket');
212
-        }
213
-    }
30
+	/**
31
+	 * Maps the GraphQL input to a format that the model functions can use
32
+	 *
33
+	 * @param array $input Data coming from the GraphQL mutation query input
34
+	 * @return array
35
+	 * @throws Exception
36
+	 */
37
+	public static function prepareFields(array $input)
38
+	{
39
+		$args = [];
40
+
41
+		if (! empty($input['datetimes'])) {
42
+			$args['datetimes'] = array_map('sanitize_text_field', (array) $input['datetimes']);
43
+		}
44
+
45
+		if (! empty($input['description'])) {
46
+			$args['TKT_description'] = sanitize_text_field($input['description']);
47
+		}
48
+
49
+		if (! empty($input['endDate'])) {
50
+			$args['TKT_end_date'] = new DateTime(sanitize_text_field($input['endDate']));
51
+		}
52
+
53
+		if (array_key_exists('isDefault', $input)) {
54
+			$args['TKT_is_default'] = (bool) $input['isDefault'];
55
+		}
56
+
57
+		if (array_key_exists('isRequired', $input)) {
58
+			$args['TKT_required'] = (bool) $input['isRequired'];
59
+		}
60
+
61
+		if (array_key_exists('isTaxable', $input)) {
62
+			$args['TKT_taxable'] = (bool) $input['isTaxable'];
63
+		}
64
+
65
+		if (array_key_exists('isTrashed', $input)) {
66
+			$args['TKT_deleted'] = (bool) $input['isTrashed'];
67
+		}
68
+
69
+		if (array_key_exists('max', $input)) {
70
+			$args['TKT_max'] = (int) $input['max'];
71
+		}
72
+
73
+		if (array_key_exists('min', $input)) {
74
+			$args['TKT_min'] = (int) $input['min'];
75
+		}
76
+
77
+		if (! empty($input['name'])) {
78
+			$args['TKT_name'] = sanitize_text_field($input['name']);
79
+		}
80
+
81
+		if (array_key_exists('order', $input)) {
82
+			$args['TKT_order'] = (int) $input['order'];
83
+		}
84
+
85
+		if (! empty($input['parent'])) {
86
+			$parts = Relay::fromGlobalId(sanitize_text_field($input['parent']));
87
+			$args['TKT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null;
88
+		}
89
+
90
+		if (! empty($input['price'])) {
91
+			$args['TKT_price'] = (float) $input['price'];
92
+		}
93
+
94
+		if (! empty($input['prices'])) {
95
+			$args['prices'] = array_map('sanitize_text_field', (array) $input['prices']);
96
+		}
97
+
98
+		if (array_key_exists('quantity', $input)) {
99
+			$args['TKT_qty'] = (int) $input['quantity'];
100
+		}
101
+
102
+		if (array_key_exists('reserved', $input)) {
103
+			$args['TKT_reserved'] = (int) $input['reserved'];
104
+		}
105
+
106
+		if (array_key_exists('reverseCalculate', $input)) {
107
+			$args['TKT_reverse_calculate'] = (bool) $input['reverseCalculate'];
108
+		}
109
+
110
+		if (array_key_exists('row', $input)) {
111
+			$args['TKT_row'] = (int) $input['row'];
112
+		}
113
+
114
+		if (array_key_exists('sold', $input)) {
115
+			$args['TKT_sold'] = (int) $input['sold'];
116
+		}
117
+
118
+		if (! empty($input['startDate'])) {
119
+			$args['TKT_start_date'] = new DateTime(sanitize_text_field($input['startDate']));
120
+		}
121
+
122
+		if (array_key_exists('uses', $input)) {
123
+			$args['TKT_uses'] = (int) $input['uses'];
124
+		}
125
+
126
+		if (! empty($input['wpUser'])) {
127
+			$parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser']));
128
+			$args['TKT_wp_user'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null;
129
+		}
130
+
131
+		return $args;
132
+	}
133
+
134
+
135
+	/**
136
+	 * Sets the related datetimes for the given ticket.
137
+	 *
138
+	 * @param EE_Ticket $entity    The Ticket instance.
139
+	 * @param array     $datetimes Array of datetime IDs to relate.
140
+	 * @throws EE_Error
141
+	 * @throws InvalidArgumentException
142
+	 * @throws InvalidDataTypeException
143
+	 * @throws InvalidInterfaceException
144
+	 * @throws ReflectionException
145
+	 */
146
+	public static function setRelatedDatetimes($entity, array $datetimes)
147
+	{
148
+		$relationName = 'Datetime';
149
+		// Remove all the existing related datetimes
150
+
151
+		$entity->_remove_relations($relationName);
152
+		// @todo replace loop with single query
153
+		foreach ($datetimes as $ID) {
154
+			$parts = Relay::fromGlobalId($ID);
155
+			if (! empty($parts['id']) && absint($parts['id'])) {
156
+				$entity->_add_relation_to(
157
+					$parts['id'],
158
+					$relationName
159
+				);
160
+			}
161
+		}
162
+	}
163
+
164
+
165
+	/**
166
+	 * Sets the related prices for the given ticket.
167
+	 *
168
+	 * @param EE_Ticket $entity The Ticket instance.
169
+	 * @param array     $prices Array of entity IDs to relate.
170
+	 * @throws EE_Error
171
+	 * @throws InvalidArgumentException
172
+	 * @throws InvalidDataTypeException
173
+	 * @throws InvalidInterfaceException
174
+	 * @throws ReflectionException
175
+	 */
176
+	public static function setRelatedPrices($entity, array $prices)
177
+	{
178
+		$relationName = 'Price';
179
+		// Remove all the existing related entities
180
+		$entity->_remove_relations($relationName);
181
+
182
+		// @todo replace loop with single query
183
+		foreach ($prices as $ID) {
184
+			$parts = Relay::fromGlobalId($ID);
185
+			if (! empty($parts['id']) && absint($parts['id'])) {
186
+				$entity->_add_relation_to(
187
+					$parts['id'],
188
+					$relationName
189
+				);
190
+			}
191
+		}
192
+	}
193
+
194
+
195
+	/**
196
+	 * @param EE_Ticket  $ticket_entity
197
+	 * @param EEM_Ticket $ticket_model
198
+	 * @throws EE_Error
199
+	 * @throws InvalidArgumentException
200
+	 * @throws InvalidDataTypeException
201
+	 * @throws InvalidInterfaceException
202
+	 * @throws ReflectionException
203
+	 * @since $VID:$
204
+	 */
205
+	public static function addDefaultPrices(EE_Ticket $ticket_entity, EEM_Ticket $ticket_model)
206
+	{
207
+		$price_model = EEM_Price::instance();
208
+		$default_prices = $price_model->get_all_default_prices();
209
+		foreach ($default_prices as $default_price) {
210
+			$default_price->save();
211
+			$default_price->_add_relation_to($ticket_entity, 'Ticket');
212
+		}
213
+	}
214 214
 }
Please login to merge, or discard this patch.
core/domain/services/graphql/mutators/TicketCreate.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
          * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
31 31
          * @return array
32 32
          */
33
-        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
33
+        return static function($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
34 34
             try {
35 35
 
36 36
                 EntityMutator::checkPermissions($model);
@@ -53,11 +53,11 @@  discard block
 block discarded – undo
53 53
                 $id = $entity->save();
54 54
                 EntityMutator::validateResults($id);
55 55
 
56
-                if (! empty($datetimes)) {
56
+                if ( ! empty($datetimes)) {
57 57
                     TicketMutation::setRelatedDatetimes($entity, $datetimes);
58 58
                 }
59 59
                 // if prices are passed.
60
-                if (! empty($prices)) {
60
+                if ( ! empty($prices)) {
61 61
                     TicketMutation::setRelatedPrices($entity, $prices);
62 62
                 } else {
63 63
                     TicketMutation::addDefaultPrices($entity, $model);
Please login to merge, or discard this patch.
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -13,67 +13,67 @@
 block discarded – undo
13 13
 class TicketCreate extends EntityMutator
14 14
 {
15 15
 
16
-    /**
17
-     * Defines the mutation data modification closure.
18
-     *
19
-     * @param EEM_Ticket $model
20
-     * @param Ticket     $type
21
-     * @return callable
22
-     */
23
-    public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $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);
16
+	/**
17
+	 * Defines the mutation data modification closure.
18
+	 *
19
+	 * @param EEM_Ticket $model
20
+	 * @param Ticket     $type
21
+	 * @return callable
22
+	 */
23
+	public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $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 36
 
37
-                $datetimes = [];
38
-                $prices = [];
37
+				$datetimes = [];
38
+				$prices = [];
39 39
 
40
-                $args = TicketMutation::prepareFields($input);
40
+				$args = TicketMutation::prepareFields($input);
41 41
 
42
-                if (isset($args['datetimes'])) {
43
-                    $datetimes = $args['datetimes'];
44
-                    unset($args['datetimes']);
45
-                }
46
-                if (isset($args['prices'])) {
47
-                    $prices = $args['prices'];
48
-                    unset($args['prices']);
49
-                }
42
+				if (isset($args['datetimes'])) {
43
+					$datetimes = $args['datetimes'];
44
+					unset($args['datetimes']);
45
+				}
46
+				if (isset($args['prices'])) {
47
+					$prices = $args['prices'];
48
+					unset($args['prices']);
49
+				}
50 50
 
51
-                $entity = EE_Ticket::new_instance($args);
52
-                $id = $entity->save();
53
-                EntityMutator::validateResults($id);
51
+				$entity = EE_Ticket::new_instance($args);
52
+				$id = $entity->save();
53
+				EntityMutator::validateResults($id);
54 54
 
55
-                if (! empty($datetimes)) {
56
-                    TicketMutation::setRelatedDatetimes($entity, $datetimes);
57
-                }
58
-                // if prices are passed.
59
-                if (! empty($prices)) {
60
-                    TicketMutation::setRelatedPrices($entity, $prices);
61
-                } else {
62
-                    TicketMutation::addDefaultPrices($entity, $model);
63
-                }
64
-            } catch (Exception $exception) {
65
-                EntityMutator::handleExceptions(
66
-                    $exception,
67
-                    esc_html__(
68
-                        'The ticket could not be created because of the following error(s)',
69
-                        'event_espresso'
70
-                    )
71
-                );
72
-            }
55
+				if (! empty($datetimes)) {
56
+					TicketMutation::setRelatedDatetimes($entity, $datetimes);
57
+				}
58
+				// if prices are passed.
59
+				if (! empty($prices)) {
60
+					TicketMutation::setRelatedPrices($entity, $prices);
61
+				} else {
62
+					TicketMutation::addDefaultPrices($entity, $model);
63
+				}
64
+			} catch (Exception $exception) {
65
+				EntityMutator::handleExceptions(
66
+					$exception,
67
+					esc_html__(
68
+						'The ticket could not be created because of the following error(s)',
69
+						'event_espresso'
70
+					)
71
+				);
72
+			}
73 73
 
74
-            return [
75
-                'id' => $id,
76
-            ];
77
-        };
78
-    }
74
+			return [
75
+				'id' => $id,
76
+			];
77
+		};
78
+	}
79 79
 }
Please login to merge, or discard this patch.
core/domain/services/graphql/mutators/PriceCreate.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@
 block discarded – undo
31 31
          * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
32 32
          * @return array
33 33
          */
34
-        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
34
+        return static function($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
35 35
             try {
36 36
 
37 37
                 EntityMutator::checkPermissions($model);
Please login to merge, or discard this patch.
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -14,52 +14,52 @@
 block discarded – undo
14 14
 class PriceCreate extends EntityMutator
15 15
 {
16 16
 
17
-    /**
18
-     * Defines the mutation data modification closure.
19
-     *
20
-     * @param EEM_Price $model
21
-     * @param Price     $type
22
-     * @return callable
23
-     */
24
-    public static function mutateAndGetPayload(EEM_Price $model, Price $type)
25
-    {
26
-        /**
27
-         * Creates an entity.
28
-         *
29
-         * @param array       $input   The input for the mutation
30
-         * @param AppContext  $context The AppContext passed down to all resolvers
31
-         * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
32
-         * @return array
33
-         */
34
-        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
35
-            try {
36
-                EntityMutator::checkPermissions($model);
17
+	/**
18
+	 * Defines the mutation data modification closure.
19
+	 *
20
+	 * @param EEM_Price $model
21
+	 * @param Price     $type
22
+	 * @return callable
23
+	 */
24
+	public static function mutateAndGetPayload(EEM_Price $model, Price $type)
25
+	{
26
+		/**
27
+		 * Creates an entity.
28
+		 *
29
+		 * @param array       $input   The input for the mutation
30
+		 * @param AppContext  $context The AppContext passed down to all resolvers
31
+		 * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
32
+		 * @return array
33
+		 */
34
+		return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
35
+			try {
36
+				EntityMutator::checkPermissions($model);
37 37
 
38
-                $args = PriceMutation::prepareFields($input);
38
+				$args = PriceMutation::prepareFields($input);
39 39
 
40
-                if (empty($args['PRT_ID'])) {
41
-                    // translators: the placeholder is the name of the field.
42
-                    throw new UserError(
43
-                        sprintf(esc_html__('A valid %1$s must be passed.', 'event_espresso'), 'priceType')
44
-                    );
45
-                }
40
+				if (empty($args['PRT_ID'])) {
41
+					// translators: the placeholder is the name of the field.
42
+					throw new UserError(
43
+						sprintf(esc_html__('A valid %1$s must be passed.', 'event_espresso'), 'priceType')
44
+					);
45
+				}
46 46
 
47
-                $entity = EE_Price::new_instance($args);
48
-                $id = $entity->save();
49
-                EntityMutator::validateResults($id);
50
-            } catch (Exception $exception) {
51
-                EntityMutator::handleExceptions(
52
-                    $exception,
53
-                    esc_html__(
54
-                        'The price could not be created because of the following error(s)',
55
-                        'event_espresso'
56
-                    )
57
-                );
58
-            }
47
+				$entity = EE_Price::new_instance($args);
48
+				$id = $entity->save();
49
+				EntityMutator::validateResults($id);
50
+			} catch (Exception $exception) {
51
+				EntityMutator::handleExceptions(
52
+					$exception,
53
+					esc_html__(
54
+						'The price could not be created because of the following error(s)',
55
+						'event_espresso'
56
+					)
57
+				);
58
+			}
59 59
 
60
-            return [
61
-                'id' => $id,
62
-            ];
63
-        };
64
-    }
60
+			return [
61
+				'id' => $id,
62
+			];
63
+		};
64
+	}
65 65
 }
Please login to merge, or discard this patch.
core/domain/services/graphql/mutators/EventUpdate.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
          * @param ResolveInfo  $info             The ResolveInfo passed down to all resolvers
35 35
          * @return array|void
36 36
          */
37
-        return static function (
37
+        return static function(
38 38
             $id,
39 39
             array $input,
40 40
             WP_Post_Type $post_type_object,
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
         ) {
48 48
             try {
49 49
                 // Make sure we are dealing with the right entity.
50
-                if (! property_exists($post_type_object, 'graphql_single_name')
50
+                if ( ! property_exists($post_type_object, 'graphql_single_name')
51 51
                     || $post_type_object->graphql_single_name !== $type->name()) {
52 52
                     return;
53 53
                 }
Please login to merge, or discard this patch.
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -14,59 +14,59 @@
 block discarded – undo
14 14
 class EventUpdate extends EntityMutator
15 15
 {
16 16
 
17
-    /**
18
-     * Defines the mutation data modification closure.
19
-     *
20
-     * @param EEM_Event $model
21
-     * @param Event     $type
22
-     * @return callable
23
-     */
24
-    public static function mutateFields(EEM_Event $model, Event $type)
25
-    {
26
-        /**
27
-         * Update additional data related to the entity.
28
-         *
29
-         * @param int          $id               The ID of the postObject being mutated
30
-         * @param array        $input            The input for the mutation
31
-         * @param WP_Post_Type $post_type_object The Post Type Object for the type of post being mutated
32
-         * @param string       $mutation_name    The name of the mutation (ex: create, update, delete)
33
-         * @param AppContext   $context          The AppContext passed down to all resolvers
34
-         * @param ResolveInfo  $info             The ResolveInfo passed down to all resolvers
35
-         * @return array|void
36
-         */
37
-        return static function (
38
-            $id,
39
-            array $input,
40
-            WP_Post_Type $post_type_object,
41
-            $mutation_name,
42
-            AppContext $context,
43
-            ResolveInfo $info
44
-        ) use (
45
-            $model,
46
-            $type
47
-        ) {
48
-            try {
49
-                // Make sure we are dealing with the right entity.
50
-                if (! property_exists($post_type_object, 'graphql_single_name')
51
-                    || $post_type_object->graphql_single_name !== $type->name()) {
52
-                    return;
53
-                }
17
+	/**
18
+	 * Defines the mutation data modification closure.
19
+	 *
20
+	 * @param EEM_Event $model
21
+	 * @param Event     $type
22
+	 * @return callable
23
+	 */
24
+	public static function mutateFields(EEM_Event $model, Event $type)
25
+	{
26
+		/**
27
+		 * Update additional data related to the entity.
28
+		 *
29
+		 * @param int          $id               The ID of the postObject being mutated
30
+		 * @param array        $input            The input for the mutation
31
+		 * @param WP_Post_Type $post_type_object The Post Type Object for the type of post being mutated
32
+		 * @param string       $mutation_name    The name of the mutation (ex: create, update, delete)
33
+		 * @param AppContext   $context          The AppContext passed down to all resolvers
34
+		 * @param ResolveInfo  $info             The ResolveInfo passed down to all resolvers
35
+		 * @return array|void
36
+		 */
37
+		return static function (
38
+			$id,
39
+			array $input,
40
+			WP_Post_Type $post_type_object,
41
+			$mutation_name,
42
+			AppContext $context,
43
+			ResolveInfo $info
44
+		) use (
45
+			$model,
46
+			$type
47
+		) {
48
+			try {
49
+				// Make sure we are dealing with the right entity.
50
+				if (! property_exists($post_type_object, 'graphql_single_name')
51
+					|| $post_type_object->graphql_single_name !== $type->name()) {
52
+					return;
53
+				}
54 54
 
55
-                /** @var EE_Event $entity */
56
-                $entity = EntityMutator::getEntityFromID($model, $id);
57
-                $args = EventMutation::prepareFields($input, $mutation_name);
55
+				/** @var EE_Event $entity */
56
+				$entity = EntityMutator::getEntityFromID($model, $id);
57
+				$args = EventMutation::prepareFields($input, $mutation_name);
58 58
 
59
-                // Update the entity
60
-                $entity->save($args);
61
-            } catch (Exception $exception) {
62
-                EntityMutator::handleExceptions(
63
-                    $exception,
64
-                    esc_html__(
65
-                        'The datetime could not be updated because of the following error(s)',
66
-                        'event_espresso'
67
-                    )
68
-                );
69
-            }
70
-        };
71
-    }
59
+				// Update the entity
60
+				$entity->save($args);
61
+			} catch (Exception $exception) {
62
+				EntityMutator::handleExceptions(
63
+					$exception,
64
+					esc_html__(
65
+						'The datetime could not be updated because of the following error(s)',
66
+						'event_espresso'
67
+					)
68
+				);
69
+			}
70
+		};
71
+	}
72 72
 }
Please login to merge, or discard this patch.
core/domain/services/graphql/mutators/TicketDelete.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -12,44 +12,44 @@
 block discarded – undo
12 12
 class TicketDelete extends EntityMutator
13 13
 {
14 14
 
15
-    /**
16
-     * Defines the mutation data modification closure.
17
-     *
18
-     * @param EEM_Ticket $model
19
-     * @param Ticket     $type
20
-     * @return callable
21
-     */
22
-    public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type)
23
-    {
24
-        /**
25
-         * Deletes 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 ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
33
-            try {
34
-                /** @var EE_Ticket $entity */
35
-                $entity = EntityMutator::getEntityFromInputData($model, $input);
15
+	/**
16
+	 * Defines the mutation data modification closure.
17
+	 *
18
+	 * @param EEM_Ticket $model
19
+	 * @param Ticket     $type
20
+	 * @return callable
21
+	 */
22
+	public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type)
23
+	{
24
+		/**
25
+		 * Deletes 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 ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
33
+			try {
34
+				/** @var EE_Ticket $entity */
35
+				$entity = EntityMutator::getEntityFromInputData($model, $input);
36 36
 
37
-                // Delete the entity
38
-                $result = ! empty($input['deletePermanently']) ? $entity->delete_permanently() : $entity->delete();
39
-                EntityMutator::validateResults($result);
40
-            } catch (Exception $exception) {
41
-                EntityMutator::handleExceptions(
42
-                    $exception,
43
-                    esc_html__(
44
-                        'The ticket could not be deleted because of the following error(s)',
45
-                        'event_espresso'
46
-                    )
47
-                );
48
-            }
37
+				// Delete the entity
38
+				$result = ! empty($input['deletePermanently']) ? $entity->delete_permanently() : $entity->delete();
39
+				EntityMutator::validateResults($result);
40
+			} catch (Exception $exception) {
41
+				EntityMutator::handleExceptions(
42
+					$exception,
43
+					esc_html__(
44
+						'The ticket could not be deleted because of the following error(s)',
45
+						'event_espresso'
46
+					)
47
+				);
48
+			}
49 49
 
50
-            return [
51
-                'deleted' => $entity,
52
-            ];
53
-        };
54
-    }
50
+			return [
51
+				'deleted' => $entity,
52
+			];
53
+		};
54
+	}
55 55
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
          * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
30 30
          * @return array
31 31
          */
32
-        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
32
+        return static function($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
33 33
             try {
34 34
                 /** @var EE_Ticket $entity */
35 35
                 $entity = EntityMutator::getEntityFromInputData($model, $input);
Please login to merge, or discard this patch.
core/domain/services/graphql/mutators/DatetimeUpdate.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,55 +13,55 @@
 block discarded – undo
13 13
 class DatetimeUpdate extends EntityMutator
14 14
 {
15 15
 
16
-    /**
17
-     * Defines the mutation data modification closure.
18
-     *
19
-     * @param EEM_Datetime $model
20
-     * @param Datetime     $type
21
-     * @return callable
22
-     */
23
-    public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $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_Datetime $entity */
36
-                $entity = EntityMutator::getEntityFromInputData($model, $input);
16
+	/**
17
+	 * Defines the mutation data modification closure.
18
+	 *
19
+	 * @param EEM_Datetime $model
20
+	 * @param Datetime     $type
21
+	 * @return callable
22
+	 */
23
+	public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $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_Datetime $entity */
36
+				$entity = EntityMutator::getEntityFromInputData($model, $input);
37 37
 
38
-                $tickets = [];
39
-                $args = DatetimeMutation::prepareFields($input);
38
+				$tickets = [];
39
+				$args = DatetimeMutation::prepareFields($input);
40 40
 
41
-                if (isset($args['tickets'])) {
42
-                    $tickets = $args['tickets'];
43
-                    unset($args['tickets']);
44
-                }
41
+				if (isset($args['tickets'])) {
42
+					$tickets = $args['tickets'];
43
+					unset($args['tickets']);
44
+				}
45 45
 
46
-                // Update the entity
47
-                $entity->save($args);
46
+				// Update the entity
47
+				$entity->save($args);
48 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 updated because of the following error(s)',
57
-                        'event_espresso'
58
-                    )
59
-                );
60
-            }
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 updated because of the following error(s)',
57
+						'event_espresso'
58
+					)
59
+				);
60
+			}
61 61
 
62
-            return [
63
-                'id' => $entity->ID(),
64
-            ];
65
-        };
66
-    }
62
+			return [
63
+				'id' => $entity->ID(),
64
+			];
65
+		};
66
+	}
67 67
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
          * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
31 31
          * @return array
32 32
          */
33
-        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
33
+        return static function($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
34 34
             try {
35 35
                 /** @var EE_Datetime $entity */
36 36
                 $entity = EntityMutator::getEntityFromInputData($model, $input);
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
                 // Update the entity
47 47
                 $entity->save($args);
48 48
 
49
-                if (! empty($tickets)) {
49
+                if ( ! empty($tickets)) {
50 50
                     DatetimeMutation::setRelatedTickets($entity, $tickets);
51 51
                 }
52 52
             } catch (Exception $exception) {
Please login to merge, or discard this patch.
core/domain/services/graphql/mutators/DatetimeDelete.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -12,44 +12,44 @@
 block discarded – undo
12 12
 class DatetimeDelete extends EntityMutator
13 13
 {
14 14
 
15
-    /**
16
-     * Defines the mutation data modification closure.
17
-     *
18
-     * @param EEM_Datetime $model
19
-     * @param Datetime     $type
20
-     * @return callable
21
-     */
22
-    public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type)
23
-    {
24
-        /**
25
-         * Deletes 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|void
31
-         */
32
-        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
33
-            try {
34
-                /** @var EE_Datetime $entity */
35
-                $entity = EntityMutator::getEntityFromInputData($model, $input);
15
+	/**
16
+	 * Defines the mutation data modification closure.
17
+	 *
18
+	 * @param EEM_Datetime $model
19
+	 * @param Datetime     $type
20
+	 * @return callable
21
+	 */
22
+	public static function mutateAndGetPayload(EEM_Datetime $model, Datetime $type)
23
+	{
24
+		/**
25
+		 * Deletes 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|void
31
+		 */
32
+		return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
33
+			try {
34
+				/** @var EE_Datetime $entity */
35
+				$entity = EntityMutator::getEntityFromInputData($model, $input);
36 36
 
37
-                // Delete the entity
38
-                $result = ! empty($input['deletePermanently']) ? $entity->delete_permanently() : $entity->delete();
39
-                EntityMutator::validateResults($result);
40
-            } catch (Exception $exception) {
41
-                EntityMutator::handleExceptions(
42
-                    $exception,
43
-                    esc_html__(
44
-                        'The datetime could not be deleted because of the following error(s)',
45
-                        'event_espresso'
46
-                    )
47
-                );
48
-            }
37
+				// Delete the entity
38
+				$result = ! empty($input['deletePermanently']) ? $entity->delete_permanently() : $entity->delete();
39
+				EntityMutator::validateResults($result);
40
+			} catch (Exception $exception) {
41
+				EntityMutator::handleExceptions(
42
+					$exception,
43
+					esc_html__(
44
+						'The datetime could not be deleted because of the following error(s)',
45
+						'event_espresso'
46
+					)
47
+				);
48
+			}
49 49
 
50
-            return [
51
-                'deleted' => $entity,
52
-            ];
53
-        };
54
-    }
50
+			return [
51
+				'deleted' => $entity,
52
+			];
53
+		};
54
+	}
55 55
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@
 block discarded – undo
29 29
          * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
30 30
          * @return array|void
31 31
          */
32
-        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
32
+        return static function($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
33 33
             try {
34 34
                 /** @var EE_Datetime $entity */
35 35
                 $entity = EntityMutator::getEntityFromInputData($model, $input);
Please login to merge, or discard this patch.
core/domain/services/graphql/mutators/DatetimeCreate.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,55 +13,55 @@
 block discarded – undo
13 13
 class DatetimeCreate extends EntityMutator
14 14
 {
15 15
 
16
-    /**
17
-     * Defines the mutation data modification closure.
18
-     *
19
-     * @param EEM_Datetime $model
20
-     * @param Datetime     $type
21
-     * @return callable
22
-     */
23
-    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);
16
+	/**
17
+	 * Defines the mutation data modification closure.
18
+	 *
19
+	 * @param EEM_Datetime $model
20
+	 * @param Datetime     $type
21
+	 * @return callable
22
+	 */
23
+	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 36
 
37
-                $tickets = [];
38
-                $args = DatetimeMutation::prepareFields($input);
37
+				$tickets = [];
38
+				$args = DatetimeMutation::prepareFields($input);
39 39
 
40
-                if (isset($args['tickets'])) {
41
-                    $tickets = $args['tickets'];
42
-                    unset($args['tickets']);
43
-                }
40
+				if (isset($args['tickets'])) {
41
+					$tickets = $args['tickets'];
42
+					unset($args['tickets']);
43
+				}
44 44
 
45
-                $entity = EE_Datetime::new_instance($args);
46
-                $id = $entity->save();
47
-                EntityMutator::validateResults($id);
45
+				$entity = EE_Datetime::new_instance($args);
46
+				$id = $entity->save();
47
+				EntityMutator::validateResults($id);
48 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
-            }
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 61
 
62
-            return [
63
-                'id' => $id,
64
-            ];
65
-        };
66
-    }
62
+			return [
63
+				'id' => $id,
64
+			];
65
+		};
66
+	}
67 67
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
          * @param ResolveInfo $info    The ResolveInfo passed down to all resolvers
31 31
          * @return array
32 32
          */
33
-        return static function ($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
33
+        return static function($input, AppContext $context, ResolveInfo $info) use ($model, $type) {
34 34
             try {
35 35
                 EntityMutator::checkPermissions($model);
36 36
 
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
                 $id = $entity->save();
47 47
                 EntityMutator::validateResults($id);
48 48
 
49
-                if (! empty($tickets)) {
49
+                if ( ! empty($tickets)) {
50 50
                     DatetimeMutation::setRelatedTickets($entity, $tickets);
51 51
                 }
52 52
             } catch (Exception $exception) {
Please login to merge, or discard this patch.
core/domain/services/graphql/mutators/EntityMutator.php 2 patches
Indentation   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -21,157 +21,157 @@
 block discarded – undo
21 21
 abstract class EntityMutator
22 22
 {
23 23
 
24
-    /**
25
-     * @param EEM_Base $model
26
-     * @param integer $ID
27
-     * @param string   $capability
28
-     * @return EE_Base_Class
29
-     * @throws OutOfBoundsException
30
-     * @throws UserError
31
-     * @since $VID:$
32
-     */
33
-    protected static function getEntityFromID(EEM_Base $model, $ID, $capability = 'ee_edit_events')
34
-    {
35
-        EntityMutator::checkPermissions($model, $capability);
36
-        return EntityMutator::getEntity($model, $ID);
37
-    }
24
+	/**
25
+	 * @param EEM_Base $model
26
+	 * @param integer $ID
27
+	 * @param string   $capability
28
+	 * @return EE_Base_Class
29
+	 * @throws OutOfBoundsException
30
+	 * @throws UserError
31
+	 * @since $VID:$
32
+	 */
33
+	protected static function getEntityFromID(EEM_Base $model, $ID, $capability = 'ee_edit_events')
34
+	{
35
+		EntityMutator::checkPermissions($model, $capability);
36
+		return EntityMutator::getEntity($model, $ID);
37
+	}
38 38
 
39
-    /**
40
-     * @param EEM_Base $model
41
-     * @param array    $input
42
-     * @param string   $capability
43
-     * @return EE_Base_Class
44
-     * @throws OutOfBoundsException
45
-     * @throws UserError
46
-     * @since $VID:$
47
-     */
48
-    protected static function getEntityFromInputData(EEM_Base $model, array $input, $capability = 'ee_edit_events')
49
-    {
50
-        EntityMutator::checkPermissions($model, $capability);
51
-        $ID = EntityMutator::getEntityIDFromGlobalId($model, $input);
52
-        return EntityMutator::getEntity($model, $ID);
53
-    }
39
+	/**
40
+	 * @param EEM_Base $model
41
+	 * @param array    $input
42
+	 * @param string   $capability
43
+	 * @return EE_Base_Class
44
+	 * @throws OutOfBoundsException
45
+	 * @throws UserError
46
+	 * @since $VID:$
47
+	 */
48
+	protected static function getEntityFromInputData(EEM_Base $model, array $input, $capability = 'ee_edit_events')
49
+	{
50
+		EntityMutator::checkPermissions($model, $capability);
51
+		$ID = EntityMutator::getEntityIDFromGlobalId($model, $input);
52
+		return EntityMutator::getEntity($model, $ID);
53
+	}
54 54
 
55 55
 
56
-    /**
57
-     * @param EEM_Base $model
58
-     * @param string $capability
59
-     * @throws UserError
60
-     * @since $VID:$
61
-     */
62
-    protected static function checkPermissions(EEM_Base $model, $capability = 'ee_edit_events')
63
-    {
64
-        /**
65
-         * Stop now if a user isn't allowed to execute mutation
66
-         */
67
-        if (! current_user_can($capability)) {
68
-            $model_name = $model->get_this_model_name();
69
-            $message = sprintf(
70
-                esc_html_x(
71
-                    'We\'re sorry but you do not have the required permissions to execute %1$s mutations!',
72
-                    'We\'re sorry but you do not have the required permissions to execute entity(datetime/ticket/etc) mutations!',
73
-                    'event_espresso'
74
-                ),
75
-                strtolower($model_name)
76
-            );
77
-            throw new UserError($message);
78
-        }
79
-    }
56
+	/**
57
+	 * @param EEM_Base $model
58
+	 * @param string $capability
59
+	 * @throws UserError
60
+	 * @since $VID:$
61
+	 */
62
+	protected static function checkPermissions(EEM_Base $model, $capability = 'ee_edit_events')
63
+	{
64
+		/**
65
+		 * Stop now if a user isn't allowed to execute mutation
66
+		 */
67
+		if (! current_user_can($capability)) {
68
+			$model_name = $model->get_this_model_name();
69
+			$message = sprintf(
70
+				esc_html_x(
71
+					'We\'re sorry but you do not have the required permissions to execute %1$s mutations!',
72
+					'We\'re sorry but you do not have the required permissions to execute entity(datetime/ticket/etc) mutations!',
73
+					'event_espresso'
74
+				),
75
+				strtolower($model_name)
76
+			);
77
+			throw new UserError($message);
78
+		}
79
+	}
80 80
 
81
-    /**
82
-     * @param EEM_Base $model
83
-     * @param array    $input
84
-     * @return int
85
-     * @throws OutOfBoundsException
86
-     * @since $VID:$
87
-     */
88
-    protected static function getEntityIDFromGlobalId(EEM_Base $model, array $input)
89
-    {
90
-        $id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null;
91
-        $id = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0;
92
-        if ($id > 0) {
93
-            return $id;
94
-        }
95
-        // no ID? throw an exception
96
-        $model_name = $model->get_this_model_name();
97
-        throw new OutOfBoundsException(
98
-            sprintf(
99
-                esc_html_x(
100
-                    'A missing or invalid %1$s ID was received.',
101
-                    'A missing or invalid entity(datetime/ticket/etc) ID was received.',
102
-                    'event_espresso'
103
-                ),
104
-                strtolower($model_name)
105
-            )
106
-        );
107
-    }
81
+	/**
82
+	 * @param EEM_Base $model
83
+	 * @param array    $input
84
+	 * @return int
85
+	 * @throws OutOfBoundsException
86
+	 * @since $VID:$
87
+	 */
88
+	protected static function getEntityIDFromGlobalId(EEM_Base $model, array $input)
89
+	{
90
+		$id_parts = ! empty($input['id']) ? Relay::fromGlobalId($input['id']) : null;
91
+		$id = ! empty($id_parts['id']) ? absint($id_parts['id']) : 0;
92
+		if ($id > 0) {
93
+			return $id;
94
+		}
95
+		// no ID? throw an exception
96
+		$model_name = $model->get_this_model_name();
97
+		throw new OutOfBoundsException(
98
+			sprintf(
99
+				esc_html_x(
100
+					'A missing or invalid %1$s ID was received.',
101
+					'A missing or invalid entity(datetime/ticket/etc) ID was received.',
102
+					'event_espresso'
103
+				),
104
+				strtolower($model_name)
105
+			)
106
+		);
107
+	}
108 108
 
109 109
 
110
-    /**
111
-     * @param EEM_Base $model
112
-     * @param int      $ID
113
-     * @return EE_Base_Class
114
-     * @throws OutOfBoundsException
115
-     * @since $VID:$
116
-     */
117
-    protected static function getEntity(EEM_Base $model, $ID = 0)
118
-    {
119
-        $entity = $model->get_one_by_ID($ID);
120
-        $model_name = $model->get_this_model_name();
121
-        $class_name = 'EE_' . $model_name;
122
-        if ($entity instanceof $class_name) {
123
-            return $entity;
124
-        }
125
-        // OOPS!!! invalid entity
126
-        throw new OutOfBoundsException(
127
-            sprintf(
128
-                esc_html_x(
129
-                    'A valid %1$s could not be retrieved from the database.',
130
-                    'A valid entity(datetime/ticket/etc) could not be found in the database.',
131
-                    'event_espresso'
132
-                ),
133
-                strtolower($model_name)
134
-            )
135
-        );
136
-    }
110
+	/**
111
+	 * @param EEM_Base $model
112
+	 * @param int      $ID
113
+	 * @return EE_Base_Class
114
+	 * @throws OutOfBoundsException
115
+	 * @since $VID:$
116
+	 */
117
+	protected static function getEntity(EEM_Base $model, $ID = 0)
118
+	{
119
+		$entity = $model->get_one_by_ID($ID);
120
+		$model_name = $model->get_this_model_name();
121
+		$class_name = 'EE_' . $model_name;
122
+		if ($entity instanceof $class_name) {
123
+			return $entity;
124
+		}
125
+		// OOPS!!! invalid entity
126
+		throw new OutOfBoundsException(
127
+			sprintf(
128
+				esc_html_x(
129
+					'A valid %1$s could not be retrieved from the database.',
130
+					'A valid entity(datetime/ticket/etc) could not be found in the database.',
131
+					'event_espresso'
132
+				),
133
+				strtolower($model_name)
134
+			)
135
+		);
136
+	}
137 137
 
138 138
 
139
-    /**
140
-     * @param        $results
141
-     * @param string $message
142
-     * @throws RuntimeException
143
-     * @since $VID:$
144
-     */
145
-    protected static function validateResults($results, $message = '')
146
-    {
147
-        if (empty($results)) {
148
-            $message = $message !== ''
149
-                ? $message
150
-                : esc_html__(
151
-                    'An unknown error occurred. Please check your server\'s error  logs for more information',
152
-                    'event_espresso'
153
-                );
154
-            throw new RuntimeException($message);
155
-        }
156
-    }
139
+	/**
140
+	 * @param        $results
141
+	 * @param string $message
142
+	 * @throws RuntimeException
143
+	 * @since $VID:$
144
+	 */
145
+	protected static function validateResults($results, $message = '')
146
+	{
147
+		if (empty($results)) {
148
+			$message = $message !== ''
149
+				? $message
150
+				: esc_html__(
151
+					'An unknown error occurred. Please check your server\'s error  logs for more information',
152
+					'event_espresso'
153
+				);
154
+			throw new RuntimeException($message);
155
+		}
156
+	}
157 157
 
158 158
 
159
-    /**
160
-     * @param Exception $exception
161
-     * @param string    $message_prefix
162
-     * @throws RuntimeException
163
-     * @since $VID:$
164
-     */
165
-    protected static function handleExceptions(Exception $exception, $message_prefix = '')
166
-    {
167
-        $message_prefix = $message_prefix !== ''
168
-            ? $message_prefix
169
-            : esc_html__(
170
-                'The mutation could not be executed because of the following error(s)',
171
-                'event_espresso'
172
-            );
173
-        throw new RuntimeException(
174
-            sprintf('%1$s: %2$s', $message_prefix, $exception->getMessage())
175
-        );
176
-    }
159
+	/**
160
+	 * @param Exception $exception
161
+	 * @param string    $message_prefix
162
+	 * @throws RuntimeException
163
+	 * @since $VID:$
164
+	 */
165
+	protected static function handleExceptions(Exception $exception, $message_prefix = '')
166
+	{
167
+		$message_prefix = $message_prefix !== ''
168
+			? $message_prefix
169
+			: esc_html__(
170
+				'The mutation could not be executed because of the following error(s)',
171
+				'event_espresso'
172
+			);
173
+		throw new RuntimeException(
174
+			sprintf('%1$s: %2$s', $message_prefix, $exception->getMessage())
175
+		);
176
+	}
177 177
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
         /**
65 65
          * Stop now if a user isn't allowed to execute mutation
66 66
          */
67
-        if (! current_user_can($capability)) {
67
+        if ( ! current_user_can($capability)) {
68 68
             $model_name = $model->get_this_model_name();
69 69
             $message = sprintf(
70 70
                 esc_html_x(
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
     {
119 119
         $entity = $model->get_one_by_ID($ID);
120 120
         $model_name = $model->get_this_model_name();
121
-        $class_name = 'EE_' . $model_name;
121
+        $class_name = 'EE_'.$model_name;
122 122
         if ($entity instanceof $class_name) {
123 123
             return $entity;
124 124
         }
Please login to merge, or discard this patch.