Code Duplication    Length = 25-25 lines in 2 locations

projects/packages/sync/src/class-endpoints.php 1 location

@@ 352-376 (lines=25) @@
349
	 *
350
	 * @return \WP_REST_Response
351
	 */
352
	public static function update_sync_settings( $request ) {
353
		$args = $request->get_params();
354
355
		$sync_settings = Settings::get_settings();
356
357
		foreach ( $args as $key => $value ) {
358
			if ( false !== $value ) {
359
				if ( is_numeric( $value ) ) {
360
					$value = (int) $value;
361
				}
362
363
				// special case for sending empty arrays - a string with value 'empty'.
364
				if ( 'empty' === $value ) {
365
					$value = array();
366
				}
367
368
				$sync_settings[ $key ] = $value;
369
			}
370
		}
371
372
		Settings::update_settings( $sync_settings );
373
374
		// re-fetch so we see what's really being stored.
375
		return rest_ensure_response( Settings::get_settings() );
376
	}
377
378
	/**
379
	 * Verify that request has default permissions to perform sync actions.

projects/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-sync-endpoint.php 1 location

@@ 158-182 (lines=25) @@
155
156
// POST /sites/%s/sync/settings
157
class Jetpack_JSON_API_Sync_Modify_Settings_Endpoint extends Jetpack_JSON_API_Sync_Endpoint {
158
	protected function result() {
159
		$args = $this->input();
160
161
		$sync_settings = Settings::get_settings();
162
163
		foreach ( $args as $key => $value ) {
164
			if ( $value !== false ) {
165
				if ( is_numeric( $value ) ) {
166
					$value = (int) $value;
167
				}
168
169
				// special case for sending empty arrays - a string with value 'empty'
170
				if ( $value === 'empty' ) {
171
					$value = array();
172
				}
173
174
				$sync_settings[ $key ] = $value;
175
			}
176
		}
177
178
		Settings::update_settings( $sync_settings );
179
180
		// re-fetch so we see what's really being stored
181
		return Settings::get_settings();
182
	}
183
}
184
185
// GET /sites/%s/sync/settings