Conditions | 21 |
Paths | 108 |
Total Lines | 86 |
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 |
||
25 | public function index() |
||
26 | { |
||
27 | global $opt, $tpl; |
||
28 | |||
29 | ob_start(); |
||
30 | |||
31 | //get the article name to display |
||
32 | $article = ''; |
||
33 | $language = $opt['template']['locale']; |
||
34 | if (isset($_REQUEST['page']) && |
||
35 | (mb_strpos($_REQUEST['page'], '.') === false) && |
||
36 | (mb_strpos($_REQUEST['page'], '/') === false) && |
||
37 | (mb_strpos($_REQUEST['page'], '\\') === false) |
||
38 | ) { |
||
39 | $article = $_REQUEST['page']; |
||
40 | } |
||
41 | |||
42 | if ($article === '') { |
||
43 | //no article specified |
||
44 | $tpl->redirect('index.php'); |
||
45 | } elseif (isset($_REQUEST['wiki'])) { |
||
46 | $tpl->redirect(helppageurl($article)); |
||
47 | } elseif (!file_exists($opt['stylepath'] . '/articles/' . $language . '/' . $article . '.tpl')) { |
||
48 | // does article exist in default-language? |
||
49 | $file = $opt['stylepath'] . '/articles/' . $opt['template']['default']['article_locale'] . '/' . $article . '.tpl'; |
||
50 | if (file_exists($file)) { |
||
51 | $language = $opt['template']['default']['article_locale']; |
||
52 | } elseif (file_exists($opt['stylepath'] . '/articles/EN/' . $article . '.tpl')) { |
||
53 | $language = 'EN'; |
||
54 | } else { |
||
55 | // use any |
||
56 | $language = false; |
||
57 | if ($hDir = opendir($opt['stylepath'] . '/articles/')) { |
||
58 | while ((($sFile = readdir($hDir)) !== false) && ($language === false)) { |
||
59 | if ($sFile != '.' |
||
60 | && $sFile != '..' |
||
61 | && is_dir($opt['stylepath'] . '/articles/' . $sFile) |
||
62 | && file_exists($opt['stylepath'] . '/articles/' . $sFile . '/' . $article . '.tpl') |
||
63 | ) { |
||
64 | $language = $sFile; |
||
65 | } |
||
66 | } |
||
67 | closedir($hDir); |
||
68 | } |
||
69 | |||
70 | //article doesn't exists |
||
71 | if ($language === false) { |
||
72 | $tpl->redirect('index.php'); |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | |||
77 | $tpl->name = 'articles'; |
||
78 | |||
79 | $tpl->caching = true; |
||
80 | $tpl->cache_id = 'articles|' . $language . '|' . $article; |
||
81 | $tpl->cache_lifetime = 43200; |
||
82 | |||
83 | $tpl->menuitem = $this->connection->fetchColumn( |
||
84 | 'SELECT `id` FROM `sys_menu` WHERE `href`= :href LIMIT 1', |
||
85 | [':href' => 'articles.php?page=' . urlencode($article)] |
||
86 | ); |
||
87 | if ($tpl->menuitem == 0) { |
||
88 | $tpl->redirect('index.php'); |
||
89 | } |
||
90 | |||
91 | if (!$tpl->is_cached()) { |
||
92 | $tpl->assign('article', $article); |
||
93 | $tpl->assign('language', $language); |
||
94 | |||
95 | /* prepare smarty vars for special pages ... |
||
96 | */ |
||
97 | if ($article === 'cacheinfo') { |
||
98 | require_once __DIR__ . '/../../../lib2/logic/attribute.class.php'; |
||
99 | $attributes = \attribute::getSelectableAttributesListArray(true); |
||
100 | $tpl->assign('attributes', $attributes); |
||
101 | } |
||
102 | } |
||
103 | |||
104 | $tpl->display(); |
||
105 | |||
106 | $content = ob_get_contents(); |
||
107 | ob_clean(); |
||
108 | |||
109 | return Response::create($content); |
||
110 | } |
||
111 | } |
||
112 |