Code Duplication    Length = 34-35 lines in 2 locations

core/domain/services/graphql/connection_resolvers/DatetimeConnectionResolver.php 1 location

@@ 192-226 (lines=35) @@
189
     * @param array $where_args
190
     * @return array
191
     */
192
    public function sanitizeInputFields(array $where_args)
193
    {
194
        $arg_mapping = [
195
            'eventId'   => 'EVT_ID',
196
            'ticketId'  => 'Ticket.TKT_ID',
197
        ];
198
199
        $query_args = [];
200
201
        foreach ($where_args as $arg => $value) {
202
            if (! array_key_exists($arg, $arg_mapping)) {
203
                continue;
204
            }
205
206
            if (is_array($value) && ! empty($value)) {
207
                $value = array_map(
208
                    function ($value) {
209
                        if (is_string($value)) {
210
                            $value = sanitize_text_field($value);
211
                        }
212
                        return $value;
213
                    },
214
                    $value
215
                );
216
            } elseif (is_string($value)) {
217
                $value = sanitize_text_field($value);
218
            }
219
            $query_args[ $arg_mapping[ $arg ] ] = $value;
220
        }
221
222
        /**
223
         * Return the Query Args
224
         */
225
        return ! empty($query_args) && is_array($query_args) ? $query_args : [];
226
    }
227
}
228

core/domain/services/graphql/connection_resolvers/TicketConnectionResolver.php 1 location

@@ 152-185 (lines=34) @@
149
     * @param array $where_args
150
     * @return array
151
     */
152
    public function sanitizeInputFields(array $where_args)
153
    {
154
        $arg_mapping = [
155
            'datetimeId'  => 'Datetime.DTT_ID',
156
        ];
157
158
        $query_args = [];
159
160
        foreach ($where_args as $arg => $value) {
161
            if (! array_key_exists($arg, $arg_mapping)) {
162
                continue;
163
            }
164
165
            if (is_array($value) && ! empty($value)) {
166
                $value = array_map(
167
                    function ($value) {
168
                        if (is_string($value)) {
169
                            $value = sanitize_text_field($value);
170
                        }
171
                        return $value;
172
                    },
173
                    $value
174
                );
175
            } elseif (is_string($value)) {
176
                $value = sanitize_text_field($value);
177
            }
178
            $query_args[ $arg_mapping[ $arg ] ] = $value;
179
        }
180
181
        /**
182
         * Return the Query Args
183
         */
184
        return ! empty($query_args) && is_array($query_args) ? $query_args : [];
185
    }
186
}
187