Completed
Push — update/feedback-cpt ( 392815 )
by
unknown
66:11 queued 55:38
created

Grunion_Contact_Form_Endpoint   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 57.89 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 22
loc 38
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get_items_permissions_check() 11 11 2
A get_item_permissions_check() 11 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * Plugin Name: Feedback CPT Permissions over-ride
5
 */
6
7
if ( class_exists( 'WP_REST_Posts_Controller' ) ) {
8
9
	class Grunion_Contact_Form_Endpoint extends WP_REST_Posts_Controller {
10
		/**
11
		 * Check whether a given request has proper authoriztion to view feedback items.
12
		 *
13
		 * @param  WP_REST_Request $request Full details about the request.
14
		 * @return WP_Error|boolean
15
		 */
16 View Code Duplication
		public function get_items_permissions_check( $request ) {
17
			if ( ! is_user_member_of_blog( get_current_user_id(), get_current_blog_id() ) ) {
18
				return new WP_Error(
19
					'rest_cannot_view',
20
					__( 'Sorry, you cannot view this resource.' ),
21
					array( 'status' => rest_authorization_required_code() )
22
				);
23
			}
24
25
			return true;
26
		}
27
28
		/**
29
		 * Check whether a given request has proper authoriztion to view feedback item.
30
		 *
31
		 * @param  WP_REST_Request $request Full details about the request.
32
		 * @return WP_Error|boolean
33
		 */
34 View Code Duplication
		public function get_item_permissions_check( $request ) {
35
			if ( ! is_user_member_of_blog( get_current_user_id(), get_current_blog_id() ) ) {
36
				return new WP_Error(
37
					'rest_cannot_view',
38
					__( 'Sorry, you cannot view this resource.' ),
39
					array( 'status' => rest_authorization_required_code() )
40
				);
41
			}
42
43
			return true;
44
		}
45
46
	}
47
48
}
49