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 |
||
8 | class ClassyConfig { |
||
|
|||
9 | |||
10 | protected static $vars = null; |
||
11 | |||
12 | /** |
||
13 | * Returns list of allowed variables that can be used in theme config |
||
14 | * |
||
15 | * @return array |
||
16 | */ |
||
17 | private static function get_allowed_variables() { |
||
22 | |||
23 | /** |
||
24 | * Requires config file variables |
||
25 | * |
||
26 | * @return void |
||
27 | */ |
||
28 | public static function get_vars() { |
||
65 | |||
66 | |||
67 | |||
68 | /** |
||
69 | * Retrieves config variables and then inits wordpress functionality based on them |
||
70 | */ |
||
71 | public static function init() { |
||
88 | |||
89 | |||
90 | |||
91 | /** |
||
92 | * Registers Post Types |
||
93 | * |
||
94 | * @param array $post_types |
||
95 | */ |
||
96 | View Code Duplication | private static function init_post_types( $post_types ) { |
|
109 | |||
110 | |||
111 | /** |
||
112 | * Register Post Type Wrapper |
||
113 | * |
||
114 | * @param string $name |
||
115 | * @param array $config |
||
116 | * @param string $singular |
||
117 | * @param string $multiple |
||
118 | */ |
||
119 | private static function add_post_type( $name, $config, $singular = 'Entry', $multiple = 'Entries' ) { |
||
143 | |||
144 | /** |
||
145 | * Registers taxonomies |
||
146 | * |
||
147 | * @param array $taxonomies |
||
148 | */ |
||
149 | View Code Duplication | private static function init_taxonomies( $taxonomies ) { |
|
163 | |||
164 | /** |
||
165 | * Register taxonomy wrapper |
||
166 | * |
||
167 | * @param string $name |
||
168 | * @param mixed $object_type |
||
169 | * @param array $config |
||
170 | * @param string $singular |
||
171 | * @param string $multiple |
||
172 | */ |
||
173 | private static function add_taxonomy( $name, $object_type, $config, $singular = 'Entry', $multiple = 'Entries' ) { |
||
199 | |||
200 | /** |
||
201 | * Registers Post Formats |
||
202 | * |
||
203 | * @param array $post_formats |
||
204 | */ |
||
205 | private static function init_post_formats( $post_formats ) { |
||
215 | |||
216 | /** |
||
217 | * Registers Sidebars |
||
218 | * |
||
219 | * @param array $sidebars |
||
220 | */ |
||
221 | private static function init_sidebars( $sidebars ) { |
||
246 | |||
247 | } |
||
248 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.