Conditions | 12 |
Paths | 24 |
Total Lines | 54 |
Code Lines | 34 |
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 b_marquee_smartpartner($limit, $dateFormat, $itemsSize) |
||
|
|||
31 | { |
||
32 | $block = $newObjects = []; |
||
33 | if (!defined('SMARTPARTNER_DIRNAME')) { |
||
34 | define('SMARTPARTNER_DIRNAME', 'smartpartner'); |
||
35 | } |
||
36 | require_once XOOPS_ROOT_PATH . '/modules/' . SMARTPARTNER_DIRNAME . '/include/common.php'; |
||
37 | |||
38 | // Creating the partner handler object |
||
39 | $smartpartnerPartnerHandler = smartpartner_gethandler('partner'); |
||
40 | $smartpartnerCategoryHandler = smartpartner_gethandler('category'); |
||
41 | |||
42 | // Randomize |
||
43 | $partnersObj = $smartpartnerPartnerHandler->getPartners(0, 0, _SPARTNER_STATUS_ACTIVE); |
||
44 | if (count($partnersObj) > 1) { |
||
45 | $keyArray = array_keys($partnersObj); |
||
46 | $keyRand = array_rand($keyArray, count($keyArray)); |
||
47 | for ($i = 0; ($i < count($partnersObj)) && ($i < $limit); ++$i) { |
||
48 | $newObjects[$i] = $partnersObj[$keyRand[$i]]; |
||
49 | } |
||
50 | $partnersObj = $newObjects; |
||
51 | } |
||
52 | $catId = []; |
||
53 | foreach ($partnersObj as $partnerObj) { |
||
54 | if (!in_array($partnerObj->categoryid(), $catId)) { |
||
55 | $catId[] = $partnerObj->categoryid(); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | if ($partnersObj) { |
||
60 | foreach ($catId as $j => $jValue) { |
||
61 | $categoryObj = $smartpartnerCategoryHandler->get($catId[$j]); |
||
62 | for ($i = 0, $iMax = count($partnersObj); $i < $iMax; ++$i) { |
||
63 | if ($partnersObj[$i]->categoryid() == $jValue) { |
||
64 | $smartConfig = smartpartner_getModuleConfig(); |
||
65 | if ($itemsSize > 0) { |
||
66 | $title = xoops_substr($partnersObj[$i]->title(), 0, $itemsSize + 3); |
||
67 | } else { |
||
68 | $title = $partnersObj[$i]->title(); |
||
69 | } |
||
70 | |||
71 | $block[] = [ |
||
72 | 'date' => '', |
||
73 | 'category' => '', |
||
74 | 'author' => '', |
||
75 | 'title' => $title, |
||
76 | 'link' => "<a href='" . XOOPS_URL . '/modules/smartpartner/partner.php?id=' . $partnersObj[$i]->id() . "'>" . $title . '</a>' |
||
77 | ]; |
||
78 | } |
||
79 | } |
||
80 | } |
||
81 | } |
||
82 | |||
83 | return $block; |
||
84 | } |
||
85 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.