Test Failed
Push — master ( 0e5acb...8b15ea )
by Justin
10:15 queued 04:09
created

PluginsPage::getContent()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 76
Code Lines 54

Duplication

Lines 0
Ratio 0 %

Importance

Changes 12
Bugs 2 Features 4
Metric Value
c 12
b 2
f 4
dl 0
loc 76
rs 8.9667
cc 3
eloc 54
nc 4
nop 0

How to fix   Long Method   

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
3
/**
4
 * Copyright (c) 2018 Justin Kuenzel (jukusoft.com)
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
20
/**
21
 * Project: JuKuCMS
22
 * License: Apache 2.0 license
23
 * User: Justin
24
 * Date: 07.04.2018
25
 * Time: 21:17
26
 */
27
28
class PluginsPage extends PageType {
29
30
	public function getContent(): string {
31
		$template = new DwooTemplate("pages/plugins");
32
33
		//get list with installed plugins
34
		$installed_plugins = Plugins::listInstalledPlugins();
35
36
		$array = array();
37
38
		$lang_token = substr(Registry::singleton()->getSetting("lang_token"), 0, 2);
39
40
		foreach ($installed_plugins as $plugin) {
41
			$plugin = PLugin::castPlugin($plugin);
42
43
			$array[] = array(
44
				'name' => $plugin->getName(),
45
				'title' => $plugin->getTitle(),
46
				'description' => $plugin->getDescription($lang_token),
47
				'version' => $plugin->getVersion(),
48
				'installed_version' => $plugin->getInstalledVersion(),
49
				'homepage' => $plugin->getHomepage(),
50
				'authors' => $plugin->listAuthors(),
51
				'license' => $plugin->getLicense(),
52
				'keywords' => $plugin->listKeywords(),
53
				'categories' => $plugin->listCategories(),
54
				'text' => "",
55
				'issues' => $plugin->getIssuesLink(),
56
				'source' => $plugin->getSourceLink(),
57
				'support_mail' => $plugin->getSupportMail(),
58
				'support_links' => $plugin->listSupportLinks(),
59
				'installed' => $plugin->isInstalled(),
60
				'activated' => $plugin->isActivated()
61
			);
62
		}
63
64
		//assign list with installed plugins
65
		$template->assign("installed_plugins", $array);
66
67
		//get list with all uninstalled plugins
68
		$plugins = Plugins::listUninstalledPlugins();
69
70
		$plugin_list = array();
71
72
		foreach ($plugins as $plugin) {
73
			$plugin = PLugin::castPlugin($plugin);
74
75
			//create new instance of PluginInstaller to check plugin compatibility
76
			$installer = new PluginInstaller($plugin);
77
78
			$plugin_list[] = array(
79
				'name' => $plugin->getName(),
80
				'title' => $plugin->getTitle(),
81
				'description' => $plugin->getDescription($lang_token),
82
				'version' => $plugin->getVersion(),
83
				'installed_version' => $plugin->getInstalledVersion(),
84
				'homepage' => $plugin->getHomepage(),
85
				'authors' => $plugin->listAuthors(),
86
				'license' => $plugin->getLicense(),
87
				'keywords' => $plugin->listKeywords(),
88
				'categories' => $plugin->listCategories(),
89
				'text' => "",
90
				'issues' => $plugin->getIssuesLink(),
91
				'source' => $plugin->getSourceLink(),
92
				'support_mail' => $plugin->getSupportMail(),
93
				'support_links' => $plugin->listSupportLinks(),
94
				'compatible' => $installer->checkRequirements(true),
95
				'uptodate' => true,//TODO: check, if plugin is newest version
96
				'alpha' => $plugin->isAlpha(),
97
				'beta' => $plugin->isBeta(),
98
				'installed' => $plugin->isInstalled(),
99
				'activated' => $plugin->isActivated()
100
			);
101
		}
102
103
		$template->assign("plugins", $plugin_list);
104
105
		return $template->getCode();
106
	}
107
108
	public function getFooterScripts(): string {
109
		return "<!-- page script -->
110
			<script>
111
				$(function () {
112
					/*$('#example1').DataTable();*/
113
					$('#example2').DataTable({
114
						'paging'      : true,
115
						'lengthChange': false,
116
					 	'searching'   : false,
117
					 	'ordering'    : true,
118
					 	'info'        : true,
119
					 	'autoWidth'   : false
120
					});
121
					$('#plugintable').DataTable({
122
						'paging'      : true,
123
						'lengthChange': false,
124
					 	'searching'   : false,
125
					 	'ordering'    : true,
126
					 	'info'        : true,
127
					 	'autoWidth'   : false
128
					});
129
				});
130
			</script>";
131
	}
132
133
}
134
135
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
136