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 Taxonomy extends Component | ||
| 9 | { | ||
| 10 | const CUSTOM_KEYS = [ | ||
| 11 | 'menu_name', 'plural', 'single', | ||
| 12 | ]; | ||
| 13 | |||
| 14 | const TAXONOMY_DEFAULTS = [ | ||
| 15 | 'hierarchical' => true, | ||
| 16 | 'labels' => [], | ||
| 17 | 'menu_name' => '', | ||
| 18 | 'plural' => '', | ||
| 19 | 'post_types' => [], | ||
| 20 | 'public' => true, | ||
| 21 | 'rewrite' => true, | ||
| 22 | 'show_admin_column' => true, | ||
| 23 | 'show_ui' => true, | ||
| 24 | 'single' => '', | ||
| 25 | ]; | ||
| 26 | |||
| 27 | /** | ||
| 28 | * @var array | ||
| 29 | */ | ||
| 30 | public $taxonomies = []; | ||
| 31 | |||
| 32 | /** | ||
| 33 | 	 * {@inheritdoc} | ||
| 34 | */ | ||
| 35 | public function init() | ||
| 43 | |||
| 44 | /** | ||
| 45 | * @return null|WP_Query | ||
| 46 | * @filter parse_query | ||
| 47 | */ | ||
| 48 | public function filterByTaxonomy( WP_Query $query ) | ||
| 60 | |||
| 61 | /** | ||
| 62 | * @return void | ||
| 63 | * @action restrict_manage_posts | ||
| 64 | */ | ||
| 65 | public function printFilters() | ||
| 83 | |||
| 84 | /** | ||
| 85 | * @return void | ||
| 86 | * @action register | ||
| 87 | */ | ||
| 88 | public function register() | ||
| 97 | |||
| 98 | /** | ||
| 99 | 	 * {@inheritdoc} | ||
| 100 | */ | ||
| 101 | protected function normalize() | ||
| 113 | |||
| 114 | /** | ||
| 115 | * @param mixed $labels | ||
| 116 | * @return array | ||
| 117 | */ | ||
| 118 | protected function normalizeLabels( $labels, array $args ) | ||
| 122 | |||
| 123 | /** | ||
| 124 | * @param string $menuname | ||
| 125 | * @return string | ||
| 126 | */ | ||
| 127 | protected function normalizeMenuName( $menuname, array $args ) | ||
| 133 | |||
| 134 | /** | ||
| 135 | * @param mixed $types | ||
| 136 | * @return array | ||
| 137 | */ | ||
| 138 | protected function normalizePostTypes( $types ) | ||
| 142 | |||
| 143 | /** | ||
| 144 | * @return array | ||
| 145 | */ | ||
| 146 | protected function setLabels( array $args ) | ||
| 162 | } | ||
| 163 |