Conditions | 8 |
Paths | 21 |
Total Lines | 136 |
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 |
||
29 | function caldav_editUserConfiguration($userId) |
||
30 | { |
||
31 | global $babBody, $babDB; |
||
32 | |||
33 | $babBody->setTitle(caldav_translate('CalDAV personal calendar configuration')); |
||
34 | |||
35 | /* @var $caldav Func_CalendarBackend_Caldav */ |
||
36 | $caldav = bab_functionality::get('CalendarBackend/Caldav'); |
||
37 | |||
38 | if (!$caldav) { |
||
39 | $babBody->addError(caldav_translate('Unable to instanciate "CalendarBackend/Caldav" functionality.')); |
||
40 | $babBody->addError(caldav_translate('Please check that the LibCaldav addon is correctly installed.')); |
||
41 | return; |
||
42 | } |
||
43 | |||
44 | if (!bab_isUserAdministrator() || empty($userId)) { |
||
45 | $userId = $GLOBALS['BAB_SESS_USERID']; |
||
46 | } |
||
47 | |||
48 | $userIdentifier = $caldav->getUserIdentifier($userId); |
||
49 | $userPassword = $caldav->getUserPassword($userId); |
||
50 | $useruniqueid = $caldav->getUniqueId($userId); |
||
51 | |||
52 | $srv = $babDB->db_query('SELECT id, name,use_unique_id FROM libcaldav_servers ORDER BY name'); |
||
53 | |||
54 | $csrfField = ''; |
||
55 | if (class_exists('bab_CsrfProtect')) { |
||
56 | $csrf = bab_getInstance('bab_CsrfProtect'); |
||
57 | /*@var $csrf bab_CsrfProtect */ |
||
58 | |||
59 | $csrfField = '<input type="hidden" name="babCsrfProtect" value="'.bab_toHtml($csrf->getToken()).'" />'; |
||
60 | } |
||
61 | |||
62 | $form = '<form name="spaces_configuration" method="post" action="' . $GLOBALS['babPhpSelf'] . '"> |
||
63 | '.$csrfField.' |
||
64 | <input type="hidden" name="tg" value="' . bab_toHtml(bab_rp('tg')). '"> |
||
65 | <input type="hidden" name="idx" value="saveConfiguration"> |
||
66 | <input type="hidden" name="user" value="' . bab_toHtml($userId) . '"> |
||
67 | |||
68 | <table width="90%" border="0" cellspacing="0" cellpadding="2" align="center"> |
||
69 | <tr> |
||
70 | <td class="BabLoginCadreBackground" align="center" valign="middle"> |
||
71 | <table class="BabLoginMenuBackground" width="100%" border="0" cellspacing="0" cellpadding="6" align="center"> |
||
72 | <tr> |
||
73 | <td align="left" colspan="2"><b>' . sprintf(caldav_translate('CalDav account for %s'), bab_getUserName($userId, true)) . '</b></td> |
||
74 | </tr> |
||
75 | <tr> |
||
76 | <td align="right">' . caldav_translate('Server') . '</td> |
||
77 | <td align="left"> |
||
78 | <select id=selecter name="server"> |
||
79 | '; |
||
80 | |||
81 | $selected_server = $caldav->getUserServerId($userId); |
||
82 | while($arr = $babDB->db_fetch_assoc($srv)) |
||
83 | { |
||
84 | $form .= '<option'; |
||
85 | if($arr['use_unique_id']== "true") |
||
86 | { |
||
87 | $form .= " id=need "; |
||
88 | } |
||
89 | else |
||
90 | { |
||
91 | $form .= " id=dontneed "; |
||
92 | } |
||
93 | $form .= 'value="'.bab_toHtml($arr['id']).'"'; |
||
94 | if ($selected_server == $arr['id']) |
||
95 | { |
||
96 | $form .= ' selected="selected"'; |
||
97 | } |
||
98 | $form .= '>'.bab_toHtml($arr['name']).'</option>'; |
||
99 | } |
||
100 | $form .= '</select> |
||
101 | </td> |
||
102 | </tr> |
||
103 | <tr> |
||
104 | <td align="right">' . caldav_translate('Caldav user identifier') . '</td> |
||
105 | <td align="left"><input type="text" name="user_identifier" size="20" value="' . bab_toHtml($userIdentifier) . '"></td> |
||
106 | </tr> |
||
107 | <tr> |
||
108 | <td align="right">' . caldav_translate('Caldav user password') . '</td> |
||
109 | <td align="left"><input type="password" name="user_password" size="20" value="' . bab_toHtml($userPassword) . '"></td> |
||
110 | </tr> |
||
111 | <tr id="demandeid2" display:none> |
||
112 | <td colspan="3" align="center">'.caldav_translate("This server need your unique id.").'</td> |
||
113 | </tr> |
||
114 | <tr id="demandeid" style="display:none;"'; |
||
115 | |||
116 | $form .= '> |
||
117 | <td align="right">'.caldav_translate('Caldav unique identifier') . '</td> |
||
118 | <td align="left"><input type="text" name="unique_id" size="20" value="'.bab_toHtml($useruniqueid).'"></td> |
||
119 | </tr> |
||
120 | <tr id="demandeid3" display:none> |
||
121 | <td colspan="3" align="center">'.caldav_translate("This id can be found in the Url, example: https://url.yourcaldavserver.com/xxxxx/xxxxx").'</td> |
||
122 | </tr> |
||
123 | <tr> |
||
124 | <td colspan="2" align="center"><input type="submit" value="' . caldav_translate('Save') . '" /></td> |
||
125 | </tr> |
||
126 | </table> |
||
127 | </td> |
||
128 | </tr> |
||
129 | </table> |
||
130 | </form>'; |
||
131 | |||
132 | $form .= "\n <br><script type=text/javascript> $(document).ready(function(){ |
||
133 | if($('option:selected',$('#selecter')).attr('id')=='need') |
||
134 | { |
||
135 | $('#demandeid').show(); |
||
136 | $('#demandeid2').show(); |
||
137 | $('#demandeid3').show(); |
||
138 | |||
139 | } |
||
140 | else |
||
141 | { |
||
142 | $('#demandeid').hide(); |
||
143 | $('#demandeid2').hide(); |
||
144 | $('#demandeid3').hide(); |
||
145 | } |
||
146 | $('#selecter').change(function(){ |
||
147 | if($('option:selected',this).attr('id')=='need') |
||
148 | { |
||
149 | $('#demandeid').show(); |
||
150 | $('#demandeid2').show(); |
||
151 | $('#demandeid3').show(); |
||
152 | } |
||
153 | else |
||
154 | { |
||
155 | $('#demandeid').hide(); |
||
156 | $('#demandeid2').hide(); |
||
157 | $('#demandeid3').hide(); |
||
158 | } |
||
159 | }); |
||
160 | })</script> |
||
161 | "; |
||
162 | |||
163 | $babBody->babPopup($form); |
||
164 | } |
||
165 | |||
248 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.