Completed
Push — master ( 9889b6...d0410b )
by Dennis
13s queued 10s
created

WithRequestPostAttributes   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A read_post_type_from_request() 0 7 3
1
<?php
2
/**
3
 * Provides methods to parse and get information about the post object of the import from
4
 * the request parameters.
5
 *
6
 * @since   TBD
7
 *
8
 * @package lloc\Msls\ContentImport\Importers
9
 */
10
11
namespace lloc\Msls\ContentImport\Importers;
12
13
/**
14
 * Trait WithRequestPostAttributes
15
 *
16
 * @since   TBD
17
 *
18
 * @package lloc\Msls\ContentImport\Importers
19
 */
20
trait WithRequestPostAttributes {
21
	/**
22
	 * Returns the post type read from `$_REQUEST['post_type']` if any, or a default post type.
23
	 *
24
	 * @since TBD
25
	 *
26
	 * @param string $default The default post type to return if none is specified in the `$_REQUEST` super-global.
27
	 *
28
	 * @return string Either the post type read from the `$_REQUEST` super-global, or the default value.
29
	 */
30
	protected function read_post_type_from_request( $default = 'post' ) {
31
		if ( ! isset( $_REQUEST['post_type'] ) ) {
32
			return $default;
33
		}
34
35
		return filter_var( $_REQUEST['post_type'], FILTER_SANITIZE_STRING ) ?: 'post';
36
	}
37
}
38