Code Duplication    Length = 30-31 lines in 2 locations

core/libraries/rest_api/controllers/model/Read.php 2 locations

@@ 35-65 (lines=31) @@
32
	 * @param \WP_REST_Request $request
33
	 * @return \WP_REST_Response|\WP_Error
34
	 */
35
	public static function handle_request_get_all( \WP_REST_Request $request) {
36
		$controller = new Read();
37
		try{
38
			$matches = $controller->parse_route(
39
				$request->get_route(),
40
				'~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~',
41
				array( 'version', 'model' )
42
			);
43
			$controller->set_requested_version( $matches[ 'version' ] );
44
			$model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] );
45
			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) {
46
				return $controller->send_response(
47
					new \WP_Error(
48
						'endpoint_parsing_error',
49
						sprintf(
50
							__( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ),
51
							$model_name_singular
52
						)
53
					)
54
				);
55
			}
56
			return $controller->send_response(
57
					$controller->get_entities_from_model(
58
							$controller->get_model_version_info()->load_model( $model_name_singular ),
59
							$request
60
					)
61
			);
62
		} catch( \Exception $e ) {
63
			return $controller->send_response( $e );
64
		}
65
	}
66
67
	/**
68
	 * Gets a single entity related to the model indicated in the path and its id
@@ 73-102 (lines=30) @@
70
	 * @param \WP_Rest_Request $request
71
	 * @return \WP_REST_Response|\WP_Error
72
	 */
73
	public static function handle_request_get_one( \WP_Rest_Request $request ) {
74
		$controller = new Read();
75
		try{
76
			$matches = $controller->parse_route(
77
				$request->get_route(),
78
				'~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~',
79
				array( 'version', 'model', 'id' ) );
80
			$controller->set_requested_version( $matches[ 'version' ] );
81
			$model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] );
82
			if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) {
83
				return $controller->send_response(
84
					new \WP_Error(
85
						'endpoint_parsing_error',
86
						sprintf(
87
							__( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ),
88
							$model_name_singular
89
						)
90
					)
91
				);
92
			}
93
			return $controller->send_response(
94
					$controller->get_entity_from_model(
95
							$controller->get_model_version_info()->load_model( $model_name_singular ),
96
							$request
97
						)
98
				);
99
		} catch( \Exception $e ) {
100
			return $controller->send_response( $e );
101
		}
102
	}
103
104
	/**
105
	 *