Completed
Push — master ( 29f0c5...0d72ed )
by Henry
09:47
created

Dashboard   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 82
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 5 1
B render() 0 40 5
1
<?php
2
namespace Redaxscript\Admin\View\Helper;
3
4
use Redaxscript\Admin;
5
use Redaxscript\Html;
6
use Redaxscript\Module;
7
use function array_replace_recursive;
8
9
/**
10
 * helper class to create the admin dashboard
11
 *
12
 * @since 4.1.0
13
 *
14
 * @package Redaxscript
15
 * @category View
16
 * @author Henry Ruhs
17
 */
18
19
class Dashboard extends Admin\View\ViewAbstract
20
{
21
	/**
22
	 * options of the panel
23
	 *
24
	 * @var array
25
	 */
26
27
	protected $_optionArray =
28
	[
29
		'className' =>
30
		[
31
			'list' => 'rs-admin-list-dashboard',
32
			'item' => 'rs-admin-item-dashboard'
33
		]
34
	];
35
36
	/**
37
	 * init the class
38
	 *
39
	 * @since 4.1.0
40
	 *
41
	 * @param array $optionArray options of the dashboard
42
	 *
43
	 * @return self
44
	 */
45
46
	public function init(array $optionArray = []) : self
47
	{
48
		$this->_optionArray = array_replace_recursive($this->_optionArray, $optionArray);
49
		return $this;
50
	}
51
52
	/**
53
	 * render the view
54
	 *
55
	 * @since 4.1.0
56
	 *
57
	 * @return string
58
	 */
59
60
	public function render() : string
61
	{
62
		$output = Module\Hook::trigger('adminDashboardStart');
63
		$outputItem = null;
64
		$dashboardArray = Module\Hook::collect('adminDashboard');
65
66
		/* html element */
67
68
		$element = new Html\Element();
69
		$listElement = $element->copy()->init('ul',
70
		[
71
			'class' => $this->_optionArray['className']['list']
72
		]);
73
		$itemElement = $element->copy()->init('li',
74
		[
75
			'class' => $this->_optionArray['className']['item']
76
		]);
77
78
		/* collect item output */
79
80
		foreach ($dashboardArray as $moduleArray)
81
		{
82
			foreach ($moduleArray as $valueArray)
83
			{
84
				$outputItem .= $itemElement
85
					->copy()
86
					->attr('data-column', $valueArray['column'] ? : 1)
87
					->html($valueArray['content']);
88
			}
89
		}
90
91
		/* collect output */
92
93
		if ($outputItem)
0 ignored issues
show
Bug Best Practice introduced by redaxmedia
The expression $outputItem of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
94
		{
95
			$output .= $listElement->html($outputItem);
96
		}
97
		$output .= Module\Hook::trigger('adminDashboardEnd');
98
		return $output;
99
	}
100
}
101