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 |
||
3 | class Jetpack_Sync_Module_Meta extends Jetpack_Sync_Module { |
||
4 | private $meta_types = array( 'post', 'comment' ); |
||
5 | private $post_meta_whitelist = array(); |
||
6 | |||
7 | public function name() { |
||
10 | |||
11 | public function set_defaults() { |
||
15 | |||
16 | /** |
||
17 | * This implementation of get_objects_by_id() is a bit hacky since we're not passing in an array of meta IDs, |
||
18 | * but instead an array of post or comment IDs for which to retrieve meta for. On top of that, |
||
19 | * we also pass in an associative array where we expect there to be 'meta_key' and 'ids' keys present. |
||
20 | * |
||
21 | * This seemed to be required since if we have missing meta on WP.com and need to fetch it, we don't know what |
||
22 | * the meta key is, but we do know that we have missing meta for a given post or comment. |
||
23 | * |
||
24 | * @param string $object_type The type of object for which we retrieve meta. Either 'post' or 'comment' |
||
25 | * @param array $config Must include 'meta_key' and 'ids' keys |
||
26 | * |
||
27 | * @return array |
||
28 | */ |
||
29 | public function get_objects_by_id( $object_type, $config ) { |
||
77 | |||
78 | public function init_listeners( $callable ) { |
||
90 | // POST Meta |
||
91 | function update_post_meta_whitelist() { |
||
94 | |||
95 | function set_post_meta_whitelist( $post_meta ) { |
||
98 | |||
99 | function get_post_meta_whitelist() { |
||
102 | |||
103 | function is_whitelisted_post_meta( $option ) { |
||
106 | |||
107 | // Comment Meta |
||
108 | function update_comment_meta_whitelist() { |
||
111 | |||
112 | function set_comment_meta_whitelist( $comment_meta ) { |
||
115 | |||
116 | function get_comment_meta_whitelist() { |
||
119 | |||
120 | function is_whitelisted_comment_meta( $option ) { |
||
123 | |||
124 | |||
125 | /** |
||
126 | * Should we allow the meta key to be synced? |
||
127 | * |
||
128 | * @param string $meta_key The meta key. |
||
129 | * |
||
130 | * @return bool |
||
131 | */ |
||
132 | function is_meta_key_allowed( $meta_key ) { |
||
146 | |||
147 | View Code Duplication | function is_post_type_allowed( $post_id ) { |
|
154 | |||
155 | function filter_meta_post( $args ) { |
||
161 | |||
162 | function filter_meta_comment( $args ) { |
||
165 | |||
166 | } |
||
167 |
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.