Completed
Push — master ( fa6a4c...5890a8 )
by Justin
12:52 queued 09:49
created

StyleController::showPage()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 110
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 4
Metric Value
cc 4
eloc 55
c 6
b 0
f 4
nc 8
nop 3
dl 0
loc 110
rs 8.9818

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
class StyleController {
20
21
	/**
22
	 * get name of current style
23
	 *
24
	 * @param $registry Registry instance
25
	 *
26
	 * @return current style as string name
0 ignored issues
show
Bug introduced by
The type current was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
	 */
28
	public static function getCurrentStyle (Registry &$registry, Page &$page, PageType &$page_type) : string {
0 ignored issues
show
Unused Code introduced by
The parameter $page_type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

28
	public static function getCurrentStyle (Registry &$registry, Page &$page, /** @scrutinizer ignore-unused */ PageType &$page_type) : string {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $page is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

28
	public static function getCurrentStyle (Registry &$registry, /** @scrutinizer ignore-unused */ Page &$page, PageType &$page_type) : string {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
29
		//get default styles
30
		$default_style_name = Settings::get("default_style_name");
31
		$default_mobile_style_name = Settings::get("default_mobile_style_name");
32
33
		$style_name = !Browser::isMobile() ? $default_style_name : $default_mobile_style_name;
34
35
		//apply style rules
36
		$style_name = StyleRules::getStyle($registry, $style_name);
37
38
		//throw event, so plugins can change style
39
		Events::throwEvent("get_style", array(
40
			'default_style_name' => $default_style_name,
41
			'default_mobile_style_name' => $default_mobile_style_name,
42
			'style_name' => &$style_name,
43
			'registry' => $registry
44
		));
45
46
		return $style_name;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $style_name returns the type string which is incompatible with the documented return type current.
Loading history...
47
	}
48
49
	public static function showPage (Registry &$registry, Page &$page, PageType &$page_type) {
50
		//create new template
51
		$template = new DwooTemplate("index");
52
53
		$title_preafix = Settings::get("title_praefix", "");
54
		$title_suffix = Settings::get("title_suffix", "");
55
56
		//translate title
57
		$title = Translator::translateTitle($page->getTitle());
58
59
		//assign variables
60
		$template->assign("TITLE", $title_preafix . $title . $title_suffix);
61
		$template->assign("SHORT_TITLE", $title);
62
		$template->assign("RAW_TITLE", $page->getTitle());
63
		$template->assign("REGISTRY", $registry->listSettings());
64
65
		$head_content = "";
66
67
		Events::throwEvent("get_head", array(
68
			'registry' => &$registry,
69
			'page' => &$page,
70
			'page_type' => &$page_type,
71
			'head_content' => $head_content
72
		));
73
74
		$template->assign("HEAD", $head_content . $page_type->getAdditionalHeaderCode());
75
76
		$template->assign("CONTENT", $page_type->getContent());
77
		$template->assign("HEADER", $registry->getSetting("header", ""));
0 ignored issues
show
Unused Code introduced by
The call to Registry::getSetting() has too many arguments starting with ''. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

77
		$template->assign("HEADER", $registry->/** @scrutinizer ignore-call */ getSetting("header", ""));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
78
		$template->assign("FOOTER", $registry->getSetting("footer", ""));
79
		$template->assign("COPYRIGHT", Settings::get("copyright", "<strong>Copyright &copy; 2018 <a href=\"http://jukusoft.com\">JuKuSoft.com</a></strong>, All Rights Reserved."));
80
81
		$template->assign("FOOTER_SCRIPTS", $page_type->getFooterScripts());
82
83
		$template->assign("MY_GROUP_IDS", implode(",", $registry->getObject("groups")->listGroupIDs()));
84
		$template->assign("CHARSET", $page_type->getCharset());
85
86
		//create new css builder
87
		/*$css_builder = new CSSBuilder();
88
89
		//create new js builder
90
		$js_builder = new JSBuilder();
91
92
		$current_style = $registry->getSetting("current_style_name");
93
		$template->assign("CSS_HASH_ALL", $css_builder->getHash($current_style, "ALL", "header"));
94
		$template->assign("JS_HASH_ALL_HEADER", $js_builder->getHash($current_style, "ALL", "header"));
95
		$template->assign("JS_HASH_ALL_FOOTER", $js_builder->getHash($current_style, "ALL", "footer"));
96
97
		//set empty flags
98
		$template->assign("CSS_ALL_EMPTY", $css_builder->isEmpty($current_style, "ALL", "header"));
99
		$template->assign("JS_ALL_HEADER_EMPTY", $js_builder->isEmpty($current_style, "ALL", "header"));
100
		$template->assign("JS_ALL_FOOTER_EMPTY", $js_builder->isEmpty($current_style, "ALL", "footer"));*/
101
102
		//set sidebar arrays
103
		$left_sidebar = Registry::singleton()->getObject("left_sidebar");
104
		$right_sidebar = Registry::singleton()->getObject("right_sidebar");
105
		$sidebars_var = array(
106
			'left_sidebar' => $left_sidebar->listWidgetTplArray(),
107
			'right_sidebar' => $right_sidebar->listWidgetTplArray()
108
		);
109
		$template->assign("sidebars", $sidebars_var);
110
		var_dump($sidebars_var);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($sidebars_var) looks like debug code. Are you sure you do not want to remove it?
Loading history...
111
112
		//set version and build number
113
		if (PermissionChecker::current()->hasRight("can_see_cms_version")) {
114
			$template->assign("VERSION", Version::current()->getVersion());
115
			$template->assign("BUILD", Version::current()->getBuildNumber());
116
		} else {
117
			$template->assign("VERSION", "Unknown");
118
			$template->assign("BUILD", "Unknown");
119
		}
120
121
		//userid and username
122
		$user = User::current();
123
		/*$template->assign("USERID", $user->getID());
124
		$template->assign("USERNAME", $user->getUsername());*/
125
		$template->assign("IS_LOGGED_IN", $user->isLoggedIn());
126
127
		//assign menu code
128
		$globalMenu = $registry->getObject("main_menu");
129
		$localMenu = $registry->getObject("local_menu");
130
		$template->assign("MENU", $globalMenu->getCode());
131
		$template->assign("LOCALMENU", $localMenu->getCode());
132
133
		if (User::current()->isLoggedIn()) {
134
			$template->assign("is_logged_in", true);
135
			//$template->parse("main.logged_in");
136
		} else {
137
			$template->assign("is_logged_in", false);
138
			//$template->parse("main.not_logged_in");
139
		}
140
141
		//throw event
142
		Events::throwEvent("show_page", array(
143
			'registry' => &$registry,
144
			'page' => &$page,
145
			'page_type' => &$page_type,
146
			'template' => &$template
147
		));
148
149
		if ($page_type->showFooter()) {
150
			$template->assign("show_footer", true);
151
			//$template->parse("main.footer");
152
		} else {
153
			$template->assign("show_footer", false);
154
		}
155
156
		//$template->parse();
157
158
		echo $template->getCode();
159
	}
160
161
}
162
163
?>
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...
164