Code Duplication    Length = 11-19 lines in 4 locations

includes/api/class-wc-rest-shipping-zone-locations-controller.php 1 location

@@ 51-68 (lines=18) @@
48
	 * @param WP_REST_Request $request
49
	 * @return WP_REST_Response|WP_Error
50
	 */
51
	public function get_items( $request ) {
52
		$zone = $this->get_zone( $request['id'] );
53
54
		if ( is_wp_error( $zone ) ) {
55
			return $zone;
56
		}
57
58
		$locations = $zone->get_zone_locations();
59
		$data      = array();
60
61
		foreach ( $locations as $location_obj ) {
62
			$location = $this->prepare_item_for_response( $location_obj, $request );
63
			$location = $this->prepare_response_for_collection( $location );
64
			$data[]   = $location;
65
		}
66
67
		return rest_ensure_response( $data );
68
	}
69
70
	/**
71
	 * Update all Shipping Zone Locations.

includes/api/class-wc-rest-shipping-zone-methods-controller.php 1 location

@@ 110-126 (lines=17) @@
107
	 * @param WP_REST_Request $request
108
	 * @return WP_REST_Response|WP_Error
109
	 */
110
	public function get_items( $request ) {
111
		$zone = $this->get_zone( $request['zone_id'] );
112
113
		if ( is_wp_error( $zone ) ) {
114
			return $zone;
115
		}
116
117
		$methods = $zone->get_shipping_methods();
118
		$data    = array();
119
120
		foreach ( $methods as $method_obj ) {
121
			$method = $this->prepare_item_for_response( $method_obj, $request );
122
			$data[] = $method;
123
		}
124
125
		return rest_ensure_response( $data );
126
	}
127
128
	/**
129
	 * Create a new shipping zone method instance.

includes/api/class-wc-rest-payment-gateways-controller.php 1 location

@@ 114-124 (lines=11) @@
111
	 * @param WP_REST_Request $request Full details about the request.
112
	 * @return WP_Error|WP_REST_Response
113
	 */
114
	public function get_items( $request ) {
115
		$payment_gateways = WC()->payment_gateways->payment_gateways();
116
		$response         = array();
117
		foreach ( $payment_gateways as $payment_gateway_id => $payment_gateway ) {
118
			$payment_gateway->id = $payment_gateway_id;
119
			$gateway             = $this->prepare_item_for_response( $payment_gateway, $request );
120
			$gateway             = $this->prepare_response_for_collection( $gateway );
121
			$response[]          = $gateway;
122
		}
123
		return rest_ensure_response( $response );
124
	}
125
126
	/**
127
	 * Get a single payment gateway.

includes/api/class-wc-rest-settings-options-controller.php 1 location

@@ 97-115 (lines=19) @@
94
	 * @param  WP_REST_Request $request
95
	 * @return WP_Error|WP_REST_Response
96
	 */
97
	public function get_items( $request ) {
98
		$settings = $this->get_group_settings( $request['group'] );
99
100
		if ( is_wp_error( $settings ) ) {
101
			return $settings;
102
		}
103
104
		$data = array();
105
106
		foreach ( $settings as $setting_obj ) {
107
			$setting = $this->prepare_item_for_response( $setting_obj, $request );
108
			$setting = $this->prepare_response_for_collection( $setting );
109
			if ( $this->is_setting_type_valid( $setting['type'] ) ) {
110
				$data[]  = $setting;
111
			}
112
		}
113
114
		return rest_ensure_response( $data );
115
	}
116
117
	/**
118
	 * Get all settings in a group.