Conditions | 22 |
Paths | 18432 |
Total Lines | 107 |
Code Lines | 69 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
227 | public function generatePage(Page $P) |
||
228 | { |
||
229 | $requesturi = $this->serviceManager->get('request')->getRequestTarget(); |
||
230 | |||
231 | $aP = [ |
||
232 | 'language' => HelperConfig::$lang, |
||
233 | 'pageconfig' => $P->cb_pageconfig, |
||
234 | 'pagetype' => $P->cb_pagetype, |
||
235 | 'subnavkey' => $P->cb_subnav, |
||
236 | 'requesturi' => $requesturi, |
||
237 | 'requesturiarray' => parse_url($requesturi), |
||
238 | 'locale_format_date' => HelperConfig::$core['locale_format_date'], |
||
239 | 'locale_format_date_time' => HelperConfig::$core['locale_format_date_time'], |
||
240 | 'maintenancemode' => HelperConfig::$core['maintenancemode'], |
||
241 | 'numberformat_decimals' => HelperConfig::$core['numberformat_decimals'], |
||
242 | 'numberformat_decimal_point' => HelperConfig::$core['numberformat_decimal_point'], |
||
243 | 'numberformat_thousands_seperator' => HelperConfig::$core['numberformat_thousands_seperator'], |
||
244 | 'customroottemplate' => $P->getCustomRootTemplate(), |
||
245 | 'headers' => $P->getHeaders(), |
||
246 | ]; |
||
247 | if (HelperConfig::$core['enable_module_customer']) { |
||
248 | $aP['isloggedin'] = \HaaseIT\HCSF\Customer\Helper::getUserData(); |
||
249 | $aP['enable_module_customer'] = true; |
||
250 | } |
||
251 | if (HelperConfig::$core['enable_module_shop']) { |
||
252 | $aP['currency'] = HelperConfig::$shop['waehrungssymbol']; |
||
253 | $aP['orderamounts'] = HelperConfig::$shop['orderamounts']; |
||
254 | if (isset(HelperConfig::$shop['vat']['full'])) { |
||
255 | $aP['vatfull'] = HelperConfig::$shop['vat']['full']; |
||
256 | } |
||
257 | if (isset(HelperConfig::$shop['vat']['reduced'])) { |
||
258 | $aP['vatreduced'] = HelperConfig::$shop['vat']['reduced']; |
||
259 | } |
||
260 | if (isset(HelperConfig::$shop['custom_order_fields'])) { |
||
261 | $aP['custom_order_fields'] = HelperConfig::$shop['custom_order_fields']; |
||
262 | } |
||
263 | $aP['enable_module_shop'] = true; |
||
264 | } |
||
265 | if (isset($P->cb_key)) { |
||
266 | $aP['path'] = pathinfo($P->cb_key); |
||
267 | } else { |
||
268 | $aP['path'] = pathinfo($aP['requesturi']); |
||
269 | } |
||
270 | if ($P->cb_customcontenttemplate != NULL) { |
||
271 | $aP['customcontenttemplate'] = $P->cb_customcontenttemplate; |
||
272 | } |
||
273 | if ($P->cb_customdata != NULL) { |
||
274 | $aP['customdata'] = $P->cb_customdata; |
||
275 | } |
||
276 | if (isset($_SERVER['HTTP_REFERER'])) { |
||
277 | $aP['referer'] = $_SERVER['HTTP_REFERER']; |
||
278 | } |
||
279 | |||
280 | // if there is no subnav defined but there is a default subnav defined, use it |
||
281 | // subnavkey can be used in the templates to find out, where we are |
||
282 | if ((!isset($aP['subnavkey']) || $aP['subnavkey'] == '') && HelperConfig::$core['subnav_default'] != '') { |
||
283 | $aP['subnavkey'] = HelperConfig::$core['subnav_default']; |
||
284 | $P->cb_subnav = HelperConfig::$core['subnav_default']; |
||
285 | } |
||
286 | if ($P->cb_subnav != NULL && isset(HelperConfig::$navigation[$P->cb_subnav])) { |
||
287 | $aP['subnav'] = HelperConfig::$navigation[$P->cb_subnav]; |
||
288 | } |
||
289 | |||
290 | // Get page title, meta-keywords, meta-description |
||
291 | $aP['pagetitle'] = $P->oPayload->getTitle(); |
||
292 | $aP['keywords'] = $P->oPayload->cl_keywords; |
||
293 | $aP['description'] = $P->oPayload->cl_description; |
||
294 | |||
295 | // TODO: Add head scripts to DB |
||
296 | //if (isset($P["head_scripts"]) && $P["head_scripts"] != '') $aP["head_scripts"] = $P["head_scripts"]; |
||
297 | |||
298 | // Shopping cart infos |
||
299 | if (HelperConfig::$core['enable_module_shop']) { |
||
300 | $aP['cartinfo'] = SHelper::getShoppingcartData(); |
||
301 | } |
||
302 | |||
303 | $aP['countrylist'][] = ' | '; |
||
304 | foreach (HelperConfig::$countries['countries_' .HelperConfig::$lang] as $sKey => $sValue) { |
||
305 | $aP['countrylist'][] = $sKey.'|'.$sValue; |
||
306 | } |
||
307 | |||
308 | if ( |
||
309 | HelperConfig::$core['enable_module_shop'] |
||
310 | && ( |
||
311 | $aP['pagetype'] === 'itemoverview' |
||
312 | || $aP['pagetype'] === 'itemoverviewgrpd' |
||
313 | || $aP['pagetype'] === 'itemdetail' |
||
314 | ) |
||
315 | ) { |
||
316 | $aP = SHelper::handleItemPage($this->serviceManager, $P, $aP); |
||
317 | } |
||
318 | |||
319 | $aP['content'] = $P->oPayload->cl_html; |
||
320 | |||
321 | $aP['content'] = str_replace('@', '@', $aP['content']); // Change @ to HTML Entity -> maybe less spam mails |
||
322 | |||
323 | $aP['lang_available'] = HelperConfig::$core['lang_available']; |
||
324 | $aP['lang_detection_method'] = HelperConfig::$core['lang_detection_method']; |
||
325 | $aP['lang_by_domain'] = HelperConfig::$core['lang_by_domain']; |
||
326 | |||
327 | if (HelperConfig::$core['debug']) { |
||
328 | self::getDebug($aP, $P); |
||
329 | $aP['debugdata'] = \HaaseIT\Toolbox\Tools::$sDebug; |
||
330 | } |
||
331 | |||
332 | return $aP; |
||
333 | } |
||
334 | } |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: