| Conditions | 13 |
| Paths | 120 |
| Total Lines | 62 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 47 | public function showSocialNetwork($socialnetworks, $colspan = 4) |
||
| 48 | { |
||
| 49 | global $object, $form, $langs; |
||
| 50 | |||
| 51 | $nbofnetworks = count($socialnetworks); |
||
| 52 | $nbactive = 0; |
||
| 53 | foreach ($socialnetworks as $key => $value) { |
||
| 54 | if (!empty($object->socialnetworks[$key])) { |
||
| 55 | $nbactive++; |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | if ($nbofnetworks > 1) { |
||
| 60 | print '<tr><td><br><a class="paddingtop paddingbottom socialnetworklnk onreposition" colspan="' . $colspan . '" id="socialnetworklnk" href="#"></a>'; |
||
| 61 | //print '</td>'; |
||
| 62 | //print '<td'.($colspan ? ' colspan="'.($colspan-1).'"' : '').'>'; |
||
| 63 | //print '<br>'; |
||
| 64 | print ' <a class="paddingtop paddingbottom socialnetworklnk onreposition" href="#"><span class="badge badge-secondary socialnetworklnk">' . $nbactive . '</span></a>'; |
||
| 65 | print '</td>'; |
||
| 66 | print '</tr>'; |
||
| 67 | } |
||
| 68 | foreach ($socialnetworks as $key => $value) { |
||
| 69 | if ($value['active'] || $nbofnetworks == 1) { |
||
| 70 | print '<tr class="soc_network">'; |
||
| 71 | print '<td><label for="' . $value['label'] . '">' . $form->editfieldkey($value['label'], $key, '', $object, 0) . '</label></td>'; |
||
| 72 | print '<td colspan="3">'; |
||
| 73 | if (!empty($value['icon'])) { |
||
| 74 | print '<span class="fab ' . $value['icon'] . ' pictofixedwidth"></span>'; |
||
| 75 | } |
||
| 76 | print '<input type="text" name="' . $key . '" id="' . $key . '" class="minwidth100 maxwidth300 widthcentpercentminusx" maxlength="80" value="' . dol_escape_htmltag(GETPOSTISSET($key) ? GETPOST($key, 'alphanohtml') : (empty($object->socialnetworks[$key]) ? '' : $object->socialnetworks[$key])) . '">'; |
||
| 77 | print '</td>'; |
||
| 78 | print '</tr>'; |
||
| 79 | } elseif (!empty($object->socialnetworks[$key])) { |
||
| 80 | print '<input type="hidden" name="' . $key . '" value="' . $object->socialnetworks[$key] . '">'; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | print '<tr><td' . ($colspan ? ' colspan="' . $colspan . '"' : '') . '><hr></td></tr>'; |
||
| 84 | |||
| 85 | if ($nbofnetworks > 1) { |
||
| 86 | print '<script nonce="' . getNonce() . '" type="text/javascript"> |
||
| 87 | $("document").ready(function() { toogleSocialNetwork(false); }); |
||
| 88 | |||
| 89 | jQuery(".socialnetworklnk").click(function() { |
||
| 90 | console.log("Click on link"); |
||
| 91 | toogleSocialNetwork(true); |
||
| 92 | return false; |
||
| 93 | }); |
||
| 94 | |||
| 95 | function toogleSocialNetwork(chgCookieState) { |
||
| 96 | const lnk = $("#socialnetworklnk"); |
||
| 97 | const items = $(".soc_network"); |
||
| 98 | var cookieState = document.cookie.split(";").some((item) => item.trim().startsWith("DOLUSER_SOCIALNETWORKS_SHOW=true")) == true; |
||
| 99 | |||
| 100 | if (!chgCookieState) cookieState = !cookieState ; |
||
| 101 | |||
| 102 | if (cookieState) { |
||
| 103 | items.hide(); |
||
| 104 | lnk.text("' . dol_escape_js($langs->transnoentitiesnoconv("ShowSocialNetworks")) . '..."); |
||
| 105 | if (chgCookieState) { document.cookie = "DOLUSER_SOCIALNETWORKS_SHOW=false; SameSite=Strict"}; |
||
| 106 | } else { |
||
| 107 | items.show(); |
||
| 108 | lnk.text("' . dol_escape_js($langs->transnoentitiesnoconv("HideSocialNetworks")) . '..."); |
||
| 109 | if (chgCookieState) { document.cookie = "DOLUSER_SOCIALNETWORKS_SHOW=true; SameSite=Strict";} |
||
| 116 |