MslsContentTypes   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 85
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 5

7 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 9 2
A is_post_type() 0 3 1
A is_taxonomy() 0 3 1
A acl_request() 0 3 1
A get() 0 3 1
A get_request() 0 5 2
A get_superglobals() 0 6 1
1
<?php
2
/**
3
 * MslsContentTypes
4
 * @author Dennis Ploetner <[email protected]>
5
 * @since 0.9.8
6
 */
7
8
namespace lloc\Msls;
9
10
/**
11
 * Supported content types
12
 * @package Msls
13
 */
14
class MslsContentTypes extends MslsRegistryInstance {
15
16
	/**
17
	 * Request
18
	 * @var string
19
	 */
20
	protected $request;
21
22
	/**
23
	 * Types
24
	 * @var array
25
	 */
26
	protected $types = [];
27
28
	/**
29
	 * Factory method
30
	 *
31
	 * @codeCoverageIgnore
32
	 *
33
	 * @return MslsContentTypes
34
	 */
35
	public static function create() {
36
		$_request = ( new MslsContentTypes() )->get_superglobals( [ 'taxonomy' ] );
37
38
		if ( '' != $_request['taxonomy'] ) {
39
			return MslsTaxonomy::instance();
40
		}
41
42
		return MslsPostType::instance();
43
	}
44
45
	/**
46
	 * Check for post_type
47
	 * @return bool
48
	 */
49
	public function is_post_type() {
50
		return false;
51
	}
52
53
	/**
54
	 * Check for taxonomy
55
	 * @return bool
56
	 */
57
	public function is_taxonomy() {
58
		return false;
59
	}
60
61
	/**
62
	 * Check if the current user can manage this content type
63
	 *
64
	 * Returns name of the content type if the user has access or an empty
65
	 * string if the user can not access
66
	 *
67
	 * @return string
68
	 */
69
	public function acl_request() {
70
		return '';
71
	}
72
73
	/**
74
	 * Getter
75
	 * @return array
76
	 */
77
	public function get() {
78
		return (array) apply_filters('msls_supported_post_types', $this->types);
79
	}
80
81
	/**
82
	 * Gets the request if it is an allowed content type
83
	 * @return string
84
	 */
85
	public function get_request() {
86
		$types =  apply_filters('msls_supported_post_types', $this->types );
87
88
		return in_array( $this->request, $types ) ? $this->request : '';
89
	}
90
91
	public function get_superglobals( $arr ) {
92
		$options = MslsOptions::instance();
93
		$plugin  = new MslsPlugin( $options );
94
95
		return $plugin->get_superglobals( $arr );
96
	}
97
98
}
99