Reporter::_renderDashboard()   F
last analyzed

Complexity

Conditions 10
Paths 512

Size

Total Lines 82

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 82
rs 3.7349
c 0
b 0
f 0
cc 10
nc 512
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace Redaxscript\Modules\Reporter;
3
4
use Redaxscript\Filesystem;
5
use Redaxscript\Html;
6
use Redaxscript\Model;
7
use Redaxscript\Module;
8
9
/**
10
 * Reports on the dashboard
11
 *
12
 * @since 4.1.0
13
 *
14
 * @package Redaxscript
15
 * @category Modules
16
 * @author Henry Ruhs
17
 */
18
19
class Reporter extends Module\Metadata
20
{
21
	/**
22
	 * array of the module
23
	 *
24
	 * @var array
25
	 */
26
27
	protected static $_moduleArray =
28
	[
29
		'name' => 'Reporter',
30
		'alias' => 'Reporter',
31
		'author' => 'Redaxmedia',
32
		'description' => 'Reports on the dashboard',
33
		'version' => '4.1.1'
34
	];
35
36
	/**
37
	 * array of the option
38
	 *
39
	 * @var array
40
	 */
41
42
	protected $_optionArray =
43
	[
44
		'className' =>
45
		[
46
			'dashboard' =>
47
			[
48
				'title' => 'rs-admin-title-dashboard',
49
				'text' => 'rs-admin-text-dashboard'
50
			]
51
		]
52
	];
53
54
	/**
55
	 * adminDashboard
56
	 *
57
	 * @since 4.1.0
58
	 *
59
	 * @return array
60
	 */
61
62
	public function adminDashboard() : array
63
	{
64
		$this->setDashboard($this->_renderDashboard('categories'));
65
		$this->setDashboard($this->_renderDashboard('articles'));
66
		$this->setDashboard($this->_renderDashboard('extras'));
67
		$this->setDashboard($this->_renderDashboard('comments'));
68
		$this->setDashboard($this->_renderDashboard('users'));
69
		$this->setDashboard($this->_renderDashboard('groups'));
70
		$this->setDashboard($this->_renderDashboard('modules'));
71
		$this->setDashboard($this->_renderDashboard('languages'));
72
		$this->setDashboard($this->_renderDashboard('templates'));
73
		return $this->getDashboardArray();
74
	}
75
76
	/**
77
	 * renderDashboard
78
	 *
79
	 * @since 4.1.0
80
	 *
81
	 * @param string type
82
	 * @return string
83
	 */
84
85
	protected function _renderDashboard(string $type = null) : string
86
	{
87
		$categoryModel = new Model\Category();
88
		$articleModel = new Model\Article();
89
		$extraModel = new Model\Extra();
90
		$commentModel = new Model\Comment();
91
		$userModel = new Model\User();
92
		$groupModel = new Model\Group();
93
		$moduleModel = new Model\Module();
94
		$filesystem = new Filesystem\Filesystem();
95
		$divider = '/';
96
97
		/* html element */
98
99
		$element = new Html\Element();
100
		$titleElement = $element
101
			->copy()
102
			->init('h3',
103
			[
104
				'class' => $this->_optionArray['className']['dashboard']['title']
105
			]);
106
		$textElement = $element
107
			->copy()
108
			->init('span',
109
			[
110
				'class' => $this->_optionArray['className']['dashboard']['text']
111
			]);
112
113
		/* handle type */
114
115
		if ($type === 'categories')
116
		{
117
			$titleElement->text($categoryModel->query()->where('status', 1)->count() . $divider . $categoryModel->query()->count());
118
			$textElement->text($this->_language->get('_reporter')['categories_publish']);
119
		}
120
		if ($type === 'articles')
121
		{
122
			$titleElement->text($articleModel->query()->where('status', 1)->count() . $divider . $articleModel->query()->count());
123
			$textElement->text($this->_language->get('_reporter')['articles_publish']);
124
		}
125
		if ($type === 'extras')
126
		{
127
			$titleElement->text($extraModel->query()->where('status', 1)->count() . $divider . $extraModel->query()->count());
128
			$textElement->text($this->_language->get('_reporter')['extras_publish']);
129
		}
130
		if ($type === 'comments')
131
		{
132
			$titleElement->text($commentModel->query()->where('status', 1)->count() . $divider . $commentModel->query()->count());
133
			$textElement->text($this->_language->get('_reporter')['comments_publish']);
134
		}
135
		if ($type === 'users')
136
		{
137
			$titleElement->text($userModel->query()->where('status', 1)->count() . $divider . $userModel->query()->count());
138
			$textElement->text($this->_language->get('_reporter')['users_enable']);
139
		}
140
		if ($type === 'groups')
141
		{
142
			$titleElement->text($groupModel->query()->where('status', 1)->count() . $divider . $groupModel->query()->count());
143
			$textElement->text($this->_language->get('_reporter')['groups_enable']);
144
		}
145
		if ($type === 'modules')
146
		{
147
			$titleElement->text($moduleModel->query()->count() . $divider . $filesystem->init('modules')->countIterator());
148
			$textElement->text($this->_language->get('_reporter')['modules_install']);
149
		}
150
		if ($type === 'languages')
151
		{
152
			$titleElement->text($filesystem->init('languages')->countIterator());
153
			$textElement->text($this->_language->get('_reporter')['languages_install']);
154
		}
155
		if ($type === 'templates')
156
		{
157
			$titleElement->text($filesystem->init('templates', false,
158
			[
159
				'admin',
160
				'console',
161
				'install'
162
			])->countIterator());
163
			$textElement->text($this->_language->get('_reporter')['templates_install']);
164
		}
165
		return $titleElement . $textElement;
166
	}
167
}
168