Conditions | 16 |
Paths | 66 |
Total Lines | 75 |
Code Lines | 62 |
Lines | 3 |
Ratio | 4 % |
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 |
||
44 | public static function eventCoreFooterStart($args) |
||
45 | { |
||
46 | $xoops = Xoops::getInstance(); |
||
47 | $helper = Notifications::getInstance(); |
||
48 | |||
49 | $notifications = array(); |
||
50 | $notifications['show'] = $xoops->isModule() && $xoops->isUser() && $helper->enabled('inline') ? 1 : 0; |
||
51 | if ($notifications['show']) { |
||
52 | $helper->loadLanguage('main'); |
||
53 | $categories = $helper->getSubscribableCategories(); |
||
54 | $event_count = 0; |
||
55 | if (!empty($categories)) { |
||
56 | $notification_handler = $helper->getHandlerNotification(); |
||
57 | foreach ($categories as $category) { |
||
58 | $section['name'] = $category['name']; |
||
59 | $section['title'] = $category['title']; |
||
60 | $section['description'] = $category['description']; |
||
61 | $section['itemid'] = $category['item_id']; |
||
62 | $section['events'] = array(); |
||
63 | $subscribed_events = $notification_handler->getSubscribedEvents($category['name'], $category['item_id'], $xoops->module->getVar('mid'), $xoops->user->getVar('uid')); |
||
64 | foreach ($helper->getEvents($category['name'], true, $xoops->module->getVar('dirname')) as $event) { |
||
65 | View Code Duplication | if (!empty($event['admin_only']) && !$xoops->user->isAdmin($xoops->module->getVar('mid'))) { |
|
66 | continue; |
||
67 | } |
||
68 | if (!empty($event['invisible'])) { |
||
69 | continue; |
||
70 | } |
||
71 | $subscribed = in_array($event['name'], $subscribed_events) ? 1 : 0; |
||
72 | $section['events'][$event['name']] = array( |
||
73 | 'name' => $event['name'], |
||
74 | 'title' => $event['title'], |
||
75 | 'caption' => $event['caption'], |
||
76 | 'description' => $event['description'], |
||
77 | 'subscribed' => $subscribed |
||
78 | ); |
||
79 | ++$event_count; |
||
80 | } |
||
81 | $notifications['categories'][$category['name']] = $section; |
||
82 | } |
||
83 | $notifications['target_page'] = $helper->url('update.php'); |
||
84 | $notifications['mid'] = $xoops->module->getVar('mid'); |
||
85 | $notifications['redirect_script'] = $xoops->getEnv('PHP_SELF'); |
||
86 | $xoops->tpl()->assign(array( |
||
87 | 'lang_activenotifications' => _MD_NOTIFICATIONS_ACTIVENOTIFICATIONS, |
||
88 | 'lang_notificationoptions' => _MD_NOTIFICATIONS_NOTIFICATIONOPTIONS, |
||
89 | 'lang_updateoptions' => _MD_NOTIFICATIONS_UPDATEOPTIONS, |
||
90 | 'lang_updatenow' => _MD_NOTIFICATIONS_UPDATENOW, |
||
91 | 'lang_category' => _MD_NOTIFICATIONS_CATEGORY, |
||
92 | 'lang_event' => _MD_NOTIFICATIONS_EVENT, |
||
93 | 'lang_events' => _MD_NOTIFICATIONS_EVENTS, |
||
94 | 'lang_checkall' => _MD_NOTIFICATIONS_CHECKALL, |
||
95 | 'lang_notificationmethodis' => _MD_NOTIFICATIONS_NOTIFICATIONMETHODIS, |
||
96 | 'lang_change' => _MD_NOTIFICATIONS_CHANGE, |
||
97 | 'editprofile_url' => XOOPS_URL . '/edituser.php?uid=' . $xoops->user->getVar('uid') |
||
98 | )); |
||
99 | switch ($xoops->user->getVar('notify_method')) { |
||
100 | case NOTIFICATIONS_METHOD_DISABLE: |
||
101 | $xoops->tpl()->assign('user_method', _MD_NOTIFICATIONS_DISABLE); |
||
102 | break; |
||
103 | case NOTIFICATIONS_METHOD_PM: |
||
104 | $xoops->tpl()->assign('user_method', _MD_NOTIFICATIONS_PM); |
||
105 | break; |
||
106 | case NOTIFICATIONS_METHOD_EMAIL: |
||
107 | $xoops->tpl()->assign('user_method', _MD_NOTIFICATIONS_EMAIL); |
||
108 | break; |
||
109 | } |
||
110 | } else { |
||
111 | $notifications['show'] = 0; |
||
112 | } |
||
113 | if ($event_count == 0) { |
||
114 | $notifications['show'] = 0; |
||
115 | } |
||
116 | } |
||
117 | $xoops->tpl()->assign('notifications', $notifications); |
||
118 | } |
||
119 | |||
177 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: