Conditions | 25 |
Paths | > 20000 |
Total Lines | 91 |
Code Lines | 57 |
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 |
||
30 | function smarty_function_xoBlock($params, $smarty) |
||
|
|||
31 | { |
||
32 | if (!isset($params['id'])) { |
||
33 | return null; |
||
34 | } |
||
35 | |||
36 | $display_title = (isset($params['display']) && $params['display'] === 'title'); |
||
37 | $display_none = (isset($params['display']) && $params['display'] === 'none'); |
||
38 | $options = isset($params['options']) ? $params['options'] : false; |
||
39 | $groups = isset($params['groups']) ? explode('|', $params['groups']) : false; |
||
40 | $cache = isset($params['cache']) ? (int)$params['cache'] : false; |
||
41 | |||
42 | $block_id = (int)$params['id']; |
||
43 | |||
44 | static $block_objs; |
||
45 | if (!isset($block_objs[$block_id])) { |
||
46 | /** @var XoopsBlockHandler $blkhandler */ |
||
47 | $blkhandler = xoops_getHandler('block'); |
||
48 | $blockObj = $blkhandler->get($block_id); |
||
49 | |||
50 | if (!is_object($blockObj)) { |
||
51 | return null; |
||
52 | } |
||
53 | |||
54 | $block_objs[$block_id] = $blockObj; |
||
55 | } else { |
||
56 | $blockObj = $block_objs[$block_id]; |
||
57 | } |
||
58 | |||
59 | $user_groups = $GLOBALS['xoopsUser'] ? $GLOBALS['xoopsUser']->getGroups() : array(XOOPS_GROUP_ANONYMOUS); |
||
60 | |||
61 | static $allowed_blocks; |
||
62 | if (!is_array(@$allowed_blocks) || count($allowed_blocks) == 0) { |
||
63 | $allowed_blocks = XoopsBlock::getAllBlocksByGroup($user_groups, false); |
||
64 | } |
||
65 | |||
66 | if ($groups) { |
||
67 | if (!array_intersect($user_groups, $groups)) { |
||
68 | return null; |
||
69 | } |
||
70 | } else { |
||
71 | if (!in_array($block_id, $allowed_blocks)) { |
||
72 | return null; |
||
73 | } |
||
74 | } |
||
75 | |||
76 | if ($options) { |
||
77 | $blockObj->setVar('options', $options); |
||
78 | } |
||
79 | |||
80 | if ($cache) { |
||
81 | $blockObj->setVar('bcachetime', $cache); |
||
82 | } |
||
83 | |||
84 | if ($display_title) { |
||
85 | return $blockObj->getVar('title'); |
||
86 | } |
||
87 | |||
88 | $xoopsLogger = XoopsLogger::getInstance(); |
||
89 | $template =& $GLOBALS['xoopsTpl']; |
||
90 | |||
91 | $bcachetime = (int)$blockObj->getVar('bcachetime'); |
||
92 | if (empty($bcachetime)) { |
||
93 | $template->caching = 0; |
||
94 | } else { |
||
95 | $template->caching = 2; |
||
96 | $template->cache_lifetime = $bcachetime; |
||
97 | } |
||
98 | |||
99 | $template->setCompileId($blockObj->getVar('dirname', 'n')); |
||
100 | $tplName = ($tplName = $blockObj->getVar('template')) ? "db:{$tplName}" : 'db:system_block_dummy.tpl'; |
||
101 | $cacheid = 'blk_' . $block_id; |
||
102 | |||
103 | if (!$bcachetime || !$template->isCached($tplName, $cacheid)) { |
||
104 | $xoopsLogger->addBlock($blockObj->getVar('name')); |
||
105 | if (!($bresult = $blockObj->buildBlock())) { |
||
106 | return null; |
||
107 | } |
||
108 | if (!$display_none) { |
||
109 | $template->assign('block', $bresult); |
||
110 | $template->display($tplName, $cacheid); |
||
111 | } |
||
112 | } else { |
||
113 | $xoopsLogger->addBlock($blockObj->getVar('name'), true, $bcachetime); |
||
114 | if (!$display_none) { |
||
115 | $template->display($tplName, $cacheid); |
||
116 | } |
||
117 | } |
||
118 | $template->setCompileId($blockObj->getVar('dirname', 'n')); |
||
119 | |||
120 | return null; |
||
121 | } |
||
122 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.