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

UILoader::is_show_dashboard_widget()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
ccs 0
cts 8
cp 0
crap 6
rs 9.6666
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