Code Duplication    Length = 66-66 lines in 2 locations

includes/api/class-wc-rest-product-reviews-controller.php 1 location

@@ 42-107 (lines=66) @@
39
	/**
40
	 * Register the routes for product reviews.
41
	 */
42
	public function register_routes() {
43
		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
44
			array(
45
				'methods'             => WP_REST_Server::READABLE,
46
				'callback'            => array( $this, 'get_items' ),
47
				'permission_callback' => array( $this, 'get_items_permissions_check' ),
48
				'args'                => $this->get_collection_params(),
49
			),
50
			array(
51
				'methods'             => WP_REST_Server::CREATABLE,
52
				'callback'            => array( $this, 'create_item' ),
53
				'permission_callback' => array( $this, 'create_item_permissions_check' ),
54
				'args'                => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
55
					'review' => array(
56
						'required' => true,
57
					),
58
					'name' => array(
59
						'required' => true,
60
					),
61
					'email' => array(
62
						'required' => true,
63
					),
64
				) ),
65
			),
66
			'schema' => array( $this, 'get_public_item_schema' ),
67
		) );
68
69
		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
70
			array(
71
				'methods'             => WP_REST_Server::READABLE,
72
				'callback'            => array( $this, 'get_item' ),
73
				'permission_callback' => array( $this, 'get_item_permissions_check' ),
74
				'args'                => array(
75
					'context' => $this->get_context_param( array( 'default' => 'view' ) ),
76
				),
77
			),
78
			array(
79
				'methods'             => WP_REST_Server::EDITABLE,
80
				'callback'            => array( $this, 'update_item' ),
81
				'permission_callback' => array( $this, 'update_item_permissions_check' ),
82
				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
83
			),
84
			array(
85
				'methods'             => WP_REST_Server::DELETABLE,
86
				'callback'            => array( $this, 'delete_item' ),
87
				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
88
				'args'                => array(
89
					'force' => array(
90
						'default'     => false,
91
						'description' => __( 'Whether to bypass trash and force deletion.', 'woocommerce' ),
92
					),
93
				),
94
			),
95
			'schema' => array( $this, 'get_public_item_schema' ),
96
		) );
97
98
		register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
99
			array(
100
				'methods'             => WP_REST_Server::EDITABLE,
101
				'callback'            => array( $this, 'batch_items' ),
102
				'permission_callback' => array( $this, 'batch_items_permissions_check' ),
103
				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
104
			),
105
			'schema' => array( $this, 'get_public_batch_schema' ),
106
		) );
107
	}
108
109
	/**
110
	 * Check whether a given request has permission to read webhook deliveries.

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

@@ 56-121 (lines=66) @@
53
	/**
54
	 * Register the routes for webhooks.
55
	 */
56
	public function register_routes() {
57
		register_rest_route( $this->namespace, '/' . $this->rest_base, array(
58
			array(
59
				'methods'             => WP_REST_Server::READABLE,
60
				'callback'            => array( $this, 'get_items' ),
61
				'permission_callback' => array( $this, 'get_items_permissions_check' ),
62
				'args'                => $this->get_collection_params(),
63
			),
64
			array(
65
				'methods'             => WP_REST_Server::CREATABLE,
66
				'callback'            => array( $this, 'create_item' ),
67
				'permission_callback' => array( $this, 'create_item_permissions_check' ),
68
				'args'                => array_merge( $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), array(
69
					'topic' => array(
70
						'required' => true,
71
					),
72
					'delivery_url' => array(
73
						'required' => true,
74
					),
75
					'secret' => array(
76
						'required' => true,
77
					),
78
				) ),
79
			),
80
			'schema' => array( $this, 'get_public_item_schema' ),
81
		) );
82
83
		register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<id>[\d]+)', array(
84
			array(
85
				'methods'             => WP_REST_Server::READABLE,
86
				'callback'            => array( $this, 'get_item' ),
87
				'permission_callback' => array( $this, 'get_item_permissions_check' ),
88
				'args'                => array(
89
					'context' => $this->get_context_param( array( 'default' => 'view' ) ),
90
				),
91
			),
92
			array(
93
				'methods'             => WP_REST_Server::EDITABLE,
94
				'callback'            => array( $this, 'update_item' ),
95
				'permission_callback' => array( $this, 'update_item_permissions_check' ),
96
				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
97
			),
98
			array(
99
				'methods'             => WP_REST_Server::DELETABLE,
100
				'callback'            => array( $this, 'delete_item' ),
101
				'permission_callback' => array( $this, 'delete_item_permissions_check' ),
102
				'args'                => array(
103
					'force' => array(
104
						'default'     => false,
105
						'description' => __( 'Required to be true, as resource does not support trashing.', 'woocommerce' ),
106
					),
107
				),
108
			),
109
			'schema' => array( $this, 'get_public_item_schema' ),
110
		) );
111
112
		register_rest_route( $this->namespace, '/' . $this->rest_base . '/batch', array(
113
			array(
114
				'methods'             => WP_REST_Server::EDITABLE,
115
				'callback'            => array( $this, 'batch_items' ),
116
				'permission_callback' => array( $this, 'batch_items_permissions_check' ),
117
				'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
118
			),
119
			'schema' => array( $this, 'get_public_batch_schema' ),
120
		) );
121
	}
122
123
	/**
124
	 * Create a single webhook.