Completed
Push — 134-feature/hide-show-option-d... ( bf2631...3bb5a3 )
by Rajan
01:53
created

UILoader   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 0%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
c 5
b 0
f 0
dl 0
loc 73
ccs 0
cts 31
cp 0
rs 10
wmc 9
lcom 1
cbo 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 12 3
A is_show_dashboard_widget() 0 9 2
A initialize_components() 0 8 3
A initialize_pages() 0 5 1
1
<?php namespace EmailLog\Core\UI;
2
3
use EmailLog\Core\Loadie;
4
use EmailLog\Core\UI\Page\LogListPage;
5
6
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
7
8
/**
9
 * Admin UI Loader.
10
 * Loads and initializes all admin pages and components.
11
 *
12
 * @since 2.0
13
 */
14
class UILoader implements Loadie {
15
16
	/**
17
	 * UI Component List.
18
	 *
19
	 * @var array
20
	 */
21
	protected $components = array();
22
23
	/**
24
	 * List of Admin pages.
25
	 *
26
	 * @var \EmailLog\Core\UI\Page\BasePage[]
27
	 */
28
	protected $pages = array();
29
30
	/**
31
	 * Load all components and setup hooks.
32
	 *
33
	 * @inheritdoc
34
	 */
35
	public function load() {
36
		$this->initialize_components();
37
		$this->initialize_pages();
38
39
		foreach ( $this->components as $component ) {
40
			$component->load();
41
		}
42
43
		foreach ( $this->pages as $page ) {
44
			$page->load();
45
		}
46
	}
47
48
	public function is_show_dashboard_widget() {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
49
		$this->components['core_settings'] = new Setting\CoreSetting();
50
		$dashboard_status                  = false;
51
		$options                           = get_option( 'email-log-core' );
52
		if( isset( $options['hide_dashboard_widget'] ) ) {
53
			$dashboard_status = $options['hide_dashboard_widget'];
54
		}
55
		return $dashboard_status;
56
	}
57
58
	/**
59
	 * Initialize UI component Objects.
60
	 *
61
	 * This method may be overwritten in tests.
62
	 *
63
	 * @access protected
64
	 */
65
	protected function initialize_components() {
66
		if ( current_user_can( LogListPage::CAPABILITY ) ) {
67
			$this->components['admin_ui_enhancer'] = new Component\AdminUIEnhancer();
68
			if( ! $this->is_show_dashboard_widget() ) {
69
				$this->components['dashboard_widget']  = new Component\DashboardWidget();
70
			}
71
		}
72
	}
73
74
	/**
75
	 * Initialize Admin page Objects.
76
	 *
77
	 * This method may be overwritten in tests.
78
	 *
79
	 * @access protected
80
	 */
81
	protected function initialize_pages() {
82
		$this->pages['log_list_page']   = new Page\LogListPage();
83
		$this->pages['settings_page']   = new Page\SettingsPage();
84
		$this->pages['addon_list_page'] = new Page\AddonListPage();
85
	}
86
}
87