Completed
Push — add/sal-post ( 4a4572 )
by
unknown
10:34
created

WPCOM_JSON_API_Metadata   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 33
Duplicated Lines 60.61 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 0
cbo 0
dl 20
loc 33
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B is_public() 20 20 5
A is_internal_only() 0 10 3

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
 * Utility classes that don't necessarily have a home yet
5
 */
6
7
class WPCOM_JSON_API_Metadata {
8 View Code Duplication
	public static function is_public( $key ) {
9
		if ( empty( $key ) )
10
			return false;
11
12
		// Default whitelisted meta keys.
13
		$whitelisted_meta = array( '_thumbnail_id' );
14
15
		// whitelist of metadata that can be accessed
16
		/** This filter is documented in json-endpoints/class.wpcom-json-api-post-endpoint.php */
17
		if ( in_array( $key, apply_filters( 'rest_api_allowed_public_metadata', $whitelisted_meta ) ) )
18
			return true;
19
20
		if ( 0 === strpos( $key, 'geo_' ) )
21
			return true;
22
23
		if ( 0 === strpos( $key, '_wpas_' ) )
24
			return true;
25
26
		return false;
27
	}
28
29
	public static function is_internal_only( $key ) {
30
31
		if ( 0 === strpos( $key, '_jetpack_') )
32
			return true;
33
34
		if ( 0 === strpos( $key, '_elasticsearch_') )
35
			return true;
36
37
		return false;
38
	}
39
}