Post_Types   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 301
Duplicated Lines 34.88 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 105
loc 301
rs 10
c 0
b 0
f 0
wmc 22
lcom 0
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A register_post_types() 0 63 2
C filter_post_content() 0 58 11
A upon_deletion() 0 16 4
A __construct() 0 10 1
B register_taxonomies() 105 113 4

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
 * Custom Post Types and Taxonomies
4
 *
5
 * @package SimpleCalendar
6
 */
7
namespace SimpleCalendar;
8
9
if ( ! defined( 'ABSPATH' ) ) {
10
	exit;
11
}
12
13
/**
14
 * Custom Post Types and Taxonomies.
15
 *
16
 * Register and initialize custom post types and custom taxonomies.
17
 *
18
 * @since 3.0.0
19
 */
20
class Post_Types {
21
22
	/**
23
	 * Hook in WordPress init to register custom content.
24
	 *
25
	 * @since 3.0.0
26
	 */
27
	public function __construct() {
28
		// Register custom taxonomies.
29
		add_action( 'init', array( __CLASS__, 'register_taxonomies' ), 5 );
30
		// Register custom post types.
31
		add_action( 'init', array( __CLASS__, 'register_post_types' ), 5 );
32
		// Filter the calendar feed post content to display a calendar view.
33
		add_filter( 'the_content', array( $this, 'filter_post_content' ), 100 );
34
		// Delete calendar transients and notices upon post deletion.
35
		add_action( 'before_delete_post', array( $this, 'upon_deletion' ), 10, 1 );
36
	}
37
38
	/**
39
	 * Register custom taxonomies.
40
	 *
41
	 * @since 3.0.0
42
	 */
43
	public static function register_taxonomies() {
44
45
		do_action( 'simcal_register_taxonomies' );
46
47 View Code Duplication
		if ( ! taxonomy_exists( 'calendar_feed' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
49
			// Feed Type.
50
			$labels = array(
51
				'name'                       => __( 'Events Source Types', 'google-calendar-events' ),
52
				'singular_name'              => __( 'Events Source Type', 'google-calendar-events' ),
53
				'menu_name'                  => __( 'Events Source Type', 'google-calendar-events' ),
54
				'all_items'                  => __( 'All Events Source Types', 'google-calendar-events' ),
55
				'parent_item'                => __( 'Parent Events Source Type', 'google-calendar-events' ),
56
				'parent_item_colon'          => __( 'Parent Events Source Type:', 'google-calendar-events' ),
57
				'new_item_name'              => __( 'New Events Source Type', 'google-calendar-events' ),
58
				'add_new_item'               => __( 'Add New Events Source Type', 'google-calendar-events' ),
59
				'edit_item'                  => __( 'Edit Events Source Type', 'google-calendar-events' ),
60
				'update_item'                => __( 'Update Events Source Type', 'google-calendar-events' ),
61
				'view_item'                  => __( 'View Events Source Type', 'google-calendar-events' ),
62
				'separate_items_with_commas' => __( 'Separate events source types with commas', 'google-calendar-events' ),
63
				'add_or_remove_items'        => __( 'Add or remove events source types', 'google-calendar-events' ),
64
				'choose_from_most_used'      => __( 'Choose from the most used', 'google-calendar-events' ),
65
				'popular_items'              => __( 'Popular events source types', 'google-calendar-events' ),
66
				'search_items'               => __( 'Search Events Source Types', 'google-calendar-events' ),
67
				'not_found'                  => __( 'Not Found', 'google-calendar-events' ),
68
			);
69
70
			$args   = array(
71
				'hierarchical'      => true,
72
				'labels'            => $labels,
73
				'public'            => false,
74
				'show_admin_column' => false,
75
				'show_in_nav_menus' => false,
76
				'show_tagcloud'     => false,
77
				'show_ui'           => false,
78
			);
79
			register_taxonomy( 'calendar_feed', array( 'calendar' ), $args );
80
81
		}
82
83 View Code Duplication
		if ( ! taxonomy_exists( 'calendar_type' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
85
			// Calendar Type.
86
			$labels = array(
87
				'name'                       => __( 'Calendar Types', 'google-calendar-events' ),
88
				'singular_name'              => __( 'Calendar Type', 'google-calendar-events' ),
89
				'menu_name'                  => __( 'Calendar Type', 'google-calendar-events' ),
90
				'all_items'                  => __( 'All Calendar Types', 'google-calendar-events' ),
91
				'parent_item'                => __( 'Parent Calendar Type', 'google-calendar-events' ),
92
				'parent_item_colon'          => __( 'Parent Calendar Type:', 'google-calendar-events' ),
93
				'new_item_name'              => __( 'New Calendar Type', 'google-calendar-events' ),
94
				'add_new_item'               => __( 'Add New Calendar Type', 'google-calendar-events' ),
95
				'edit_item'                  => __( 'Edit Calendar Type', 'google-calendar-events' ),
96
				'update_item'                => __( 'Update Calendar Type', 'google-calendar-events' ),
97
				'view_item'                  => __( 'View Calendar Type', 'google-calendar-events' ),
98
				'separate_items_with_commas' => __( 'Separate calendar types with commas', 'google-calendar-events' ),
99
				'add_or_remove_items'        => __( 'Add or remove calendar types', 'google-calendar-events' ),
100
				'choose_from_most_used'      => __( 'Choose from the most used', 'google-calendar-events' ),
101
				'popular_items'              => __( 'Popular calendar types', 'google-calendar-events' ),
102
				'search_items'               => __( 'Search Calendar Types', 'google-calendar-events' ),
103
				'not_found'                  => __( 'Not Found', 'google-calendar-events' ),
104
			);
105
106
			$args   = array(
107
				'hierarchical'      => true,
108
				'labels'            => $labels,
109
				'public'            => false,
110
				'show_admin_column' => false,
111
				'show_in_nav_menus' => false,
112
				'show_tagcloud'     => false,
113
				'show_ui'           => false,
114
			);
115
			register_taxonomy( 'calendar_type', array( 'calendar' ), $args );
116
117
		}
118
119 View Code Duplication
		if ( ! taxonomy_exists( 'calendar_category' ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
120
121
			// Feed Category.
122
			$labels = array(
123
				'name'                       => __( 'Categories', 'google-calendar-events' ),
124
				'singular_name'              => __( 'Category', 'google-calendar-events' ),
125
				'menu_name'                  => __( 'Categories', 'google-calendar-events' ),
126
				'all_items'                  => __( 'All Categories', 'google-calendar-events' ),
127
				'parent_item'                => __( 'Parent Category', 'google-calendar-events' ),
128
				'parent_item_colon'          => __( 'Parent Category:', 'google-calendar-events' ),
129
				'new_item_name'              => __( 'New Category', 'google-calendar-events' ),
130
				'add_new_item'               => __( 'Add New Category', 'google-calendar-events' ),
131
				'edit_item'                  => __( 'Edit Category', 'google-calendar-events' ),
132
				'update_item'                => __( 'Update Category', 'google-calendar-events' ),
133
				'view_item'                  => __( 'View Category', 'google-calendar-events' ),
134
				'separate_items_with_commas' => __( 'Separate categories with commas', 'google-calendar-events' ),
135
				'add_or_remove_items'        => __( 'Add or remove categories', 'google-calendar-events' ),
136
				'choose_from_most_used'      => __( 'Choose from the most used', 'google-calendar-events' ),
137
				'popular_items'              => __( 'Popular Categories', 'google-calendar-events' ),
138
				'search_items'               => __( 'Search Categories', 'google-calendar-events' ),
139
				'not_found'                  => __( 'Not Found', 'google-calendar-events' ),
140
			);
141
142
			$args   = array(
143
				'hierarchical'      => true,
144
				'labels'            => $labels,
145
				'public'            => true,
146
				'show_admin_column' => true,
147
				'show_in_nav_menus' => true,
148
				'show_tagcloud'     => false,
149
				'show_ui'           => true,
150
			);
151
152
			register_taxonomy( 'calendar_category', array( 'calendar' ), $args );
153
		}
154
155
	}
156
157
	/**
158
	 * Register custom post types.
159
	 *
160
	 * @since 3.0.0
161
	 */
162
	public static function register_post_types() {
163
164
		do_action( 'simcal_register_post_types' );
165
166
		if ( ! post_type_exists( 'calendar' ) ) {
167
168
			// Calendar feed post type.
169
			$labels        = array(
170
				'name'               => _x( 'Calendars', 'Post Type General Name', 'google-calendar-events' ),
171
				'singular_name'      => _x( 'Calendar', 'Post Type Singular Name', 'google-calendar-events' ),
172
				'menu_name'          => __( 'Calendars', 'google-calendar-events' ),
173
				'name_admin_bar'     => __( 'Calendar', 'google-calendar-events' ),
174
				'parent_item_colon'  => __( 'Parent Calendar:', 'google-calendar-events' ),
175
				'all_items'          => __( 'All Calendars', 'google-calendar-events' ),
176
				'add_new_item'       => __( 'Add New Calendar', 'google-calendar-events' ),
177
				'add_new'            => __( 'Add New', 'google-calendar-events' ),
178
				'new_item'           => __( 'New Calendar', 'google-calendar-events' ),
179
				'edit_item'          => __( 'Edit Calendar', 'google-calendar-events' ),
180
				'update_item'        => __( 'Update Calendar', 'google-calendar-events' ),
181
				'view_item'          => __( 'View Calendar', 'google-calendar-events' ),
182
				'search_items'       => __( 'Search Calendar', 'google-calendar-events' ),
183
				'not_found'          => __( 'Calendars not found', 'google-calendar-events' ),
184
				'not_found_in_trash' => __( 'Calendars not found in Trash', 'google-calendar-events' ),
185
			);
186
187
			$rewrite_rules = array(
188
				'feeds'      => false,
189
				'pages'      => false,
190
				'with_front' => false,
191
				'slug'       => 'calendar',
192
			);
193
194
			$svg_icon = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iU2hhcGVzX3hBMF9JbWFnZV8xXyIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeD0iMHB4IiB5PSIwcHgiIHZpZXdCb3g9IjAgMCAxMDI0IDEwMjQiIGVuYWJsZS1iYWNrZ3JvdW5kPSJuZXcgMCAwIDEwMjQgMTAyNCIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+PHBhdGggZmlsbD0ibm9uZ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uMS00MC4zLTE3LjQtNDAuMy00MC4xYy0wLjEtNDguNS0wLjEtOTYuOSwwLTE0NS40YzAtMjIuNCwxNy41LTQwLDM5LjktNDAuMWMyMy43LTAuMSw0Ny4zLTAuMSw3MSwwYzIyLjQsMC4xLDM5LjgsMTcuNywzOS44LDQwLjFDMzc2LjgsMTUwLjksMzc2LjcsMTc1LjEsMzc2LjcsMTk5LjJ6Ii8+PHBhdGggZmlsbD0ibm9uZSIgc3Ryb2tlPSIjMDAwMDAwIiBzdHJva2UtbWl0ZXJsaW1pdD0iMTAiIGQ9Ik04MDEuNywxOTkuNmMwLDI0LDAsNDgsMCw3MmMwLDIzLjQtMTcuMyw0MC43LTQwLjcsNDAuOGMtMjMuMiwwLjEtNDYuMywwLjEtNjkuNSwwYy0yMy4xLTAuMS00MC41LTE3LjQtNDAuNS00MC41Yy0wLjEtNDguMy0wLjEtOTYuNiwwLTE0NC45YzAtMjIuNywxNy41LTQwLjIsNDAuMi00MC4zYzIzLjMtMC4xLDQ2LjYtMC4xLDcwLDBjMjMuMSwwLjEsNDAuNCwxNy40LDQwLjUsNDAuNUM4MDEuOCwxNTEuMyw4MDEuNywxNzUuNCw4MDEuNywxOTkuNnoiLz48L3N2Zz4=';
195
196
			$args          = array(
197
				'capability_type'     => 'post',
198
				'exclude_from_search' => false,
199
				'has_archive'         => false,
200
				'hierarchical'        => false,
201
				'label'               => __( 'Calendar', 'google-calendar-events' ),
202
				'labels'              => $labels,
203
				'query_var'           => true,
204
				'public'              => true,
205
				'publicly_queryable'  => true,
206
				'menu_icon'           => $svg_icon,
207
				'menu_position'       => 26.8,
208
				'rewrite'             => $rewrite_rules,
209
				'show_in_admin_bar'   => true,
210
				'show_in_menu'        => true,
211
				'show_in_nav_menus'   => true,
212
				'show_ui'             => true,
213
				'supports'            => array( 'title', 'editor' ),
214
				'taxonomies'          => array(
215
					'calendar_category',
216
					'calendar_feed',
217
					'calendar_type',
218
				),
219
			);
220
221
			register_post_type( 'calendar', $args );
222
		}
223
224
	}
225
226
	/**
227
	 * Filter post content to output a calendar.
228
	 *
229
	 * @since  3.0.0
230
	 *
231
	 * @param  string $the_content
232
	 *
233
	 * @return string
234
	 */
235
	public function filter_post_content( $the_content ) {
236
237
		if ( is_singular() ) {
238
239
			global $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
240
241
			if ( 'calendar' == $post->post_type ) {
242
243
				if ( is_admin() && ! defined( 'DOING_AJAX' ) ) {
244
					return '';
245
				} else {
246
					ob_start();
247
					simcal_print_calendar( $post );
248
					return ob_get_clean();
249
				}
250
251
			} else {
252
253
				$post_types = array();
254
				$settings   = get_option( 'simple-calendar_settings_calendars' );
255
				if ( isset( $settings['general']['attach_calendars_posts'] ) ) {
256
					$post_types = $settings['general']['attach_calendars_posts'];
257
				}
258
259
				if ( empty( $post_types ) ) {
260
					return $the_content;
261
				}
262
263
				if ( in_array( $post->post_type, (array) $post_types ) ) {
264
265
					$id = absint( get_post_meta( $post->ID, '_simcal_attach_calendar_id', true ) );
266
267
					if ( $id > 0 ) {
268
269
						$pos = esc_attr( get_post_meta( $post->ID, '_simcal_attach_calendar_position', true ) );
270
271
						ob_start();
272
273
						if ( 'after' == $pos ) {
274
							echo $the_content;
275
							simcal_print_calendar( $id );
276
						} elseif ( 'before' == $pos ) {
277
							simcal_print_calendar( $id );
278
							echo $the_content;
279
						} else {
280
							echo $the_content;
281
						}
282
283
						return ob_get_clean();
284
					}
285
				}
286
287
			}
288
289
		}
290
291
		return $the_content;
292
	}
293
294
	/**
295
	 * Upon posts deletion.
296
	 *
297
	 * Delete transients and notices when a calendar is deleted.
298
	 *
299
	 * @since 3.0.0
300
	 *
301
	 * @param $post_id
302
	 */
303
	public function upon_deletion( $post_id ) {
304
305
		$post_type = get_post_type( $post_id );
306
307
		if ( 'calendar' == $post_type ) {
308
309
			$notices = get_option( 'simple-calendar_admin_notices', array() );
310
311
			if ( ! empty( $notices ) && isset( $notices[ 'calendar_' . strval( $post_id ) ] ) ) {
312
				unset( $notices[ 'calendar_' . strval( $post_id ) ] );
313
				update_option( 'simple-calendar_admin_notices', $notices );
314
			}
315
316
			simcal_delete_feed_transients( $post_id );
317
		}
318
	}
319
320
}
321