| Conditions | 14 |
| Paths | 180 |
| Total Lines | 59 |
| Code Lines | 29 |
| 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 |
||
| 37 | public function showSocialNetwork($socialnetworks, $colspan = 4) |
||
| 38 | { |
||
| 39 | global $object, $form, $langs; |
||
| 40 | |||
| 41 | $nbofnetworks = count($socialnetworks); |
||
| 42 | $nbactive = 0; |
||
| 43 | foreach ($socialnetworks as $key => $value) { |
||
| 44 | if (!empty($object->socialnetworks[$key])) { |
||
| 45 | $nbactive++; |
||
| 46 | } |
||
| 47 | } |
||
| 48 | |||
| 49 | if ($nbofnetworks > 1) { |
||
| 50 | print '<tr><td><br><a class="paddingtop paddingbottom socialnetworklnk" id="socialnetworklnk" href="javascript:toogleSocialNetwork(true)"></a></td>'; |
||
| 51 | print '<td'.($colspan ? ' colspan="'.($colspan-1).'"' : '').'>'; |
||
| 52 | print '<br><a class="paddingtop paddingbottom socialnetworklnk" href="javascript:toogleSocialNetwork(true)"><span class="badge badge-secondary socialnetworklnk">'.$nbactive.'</span></a>'; |
||
| 53 | print '</td>'; |
||
| 54 | print '</tr>'; |
||
| 55 | } |
||
| 56 | foreach ($socialnetworks as $key => $value) { |
||
| 57 | if ($value['active'] || $nbofnetworks == 1) { |
||
| 58 | print '<tr class="soc_network">'; |
||
| 59 | print '<td><label for="'.$value['label'].'">'.$form->editfieldkey($value['label'], $key, '', $object, 0).'</label></td>'; |
||
| 60 | print '<td colspan="3">'; |
||
| 61 | if (!empty($value['icon'])) { |
||
| 62 | print '<span class="fa '.$value['icon'].' pictofixedwidth"></span>'; |
||
| 63 | } |
||
| 64 | 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])).'">'; |
||
| 65 | print '</td>'; |
||
| 66 | print '</tr>'; |
||
| 67 | } elseif (!empty($object->socialnetworks[$key])) { |
||
| 68 | print '<input type="hidden" name="'.$key.'" value="'.$object->socialnetworks[$key].'">'; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | print '<tr><td'.($colspan ? ' colspan="'.$colspan.'"' : '').'><hr></td></tr>'; |
||
| 72 | |||
| 73 | if ($nbofnetworks > 1) { |
||
| 74 | print '<script type="text/javascript"> |
||
| 75 | $("document").ready(function() { toogleSocialNetwork(false); }); |
||
| 76 | |||
| 77 | jQuery(".socialnetworklnk").onClick(function() { |
||
| 78 | console.log("Click on link"); |
||
| 79 | toogleSocialNetwork(true); |
||
| 80 | }); |
||
| 81 | |||
| 82 | function toogleSocialNetwork(chgCookieState) { |
||
| 83 | const lnk = $("#socialnetworklnk"); |
||
| 84 | const items = $(".soc_network"); |
||
| 85 | var cookieState = document.cookie.split(";").some((item) => item.trim().startsWith("DOLUSER_SOCIALNETWORKS_SHOW=true")) == true; |
||
| 86 | |||
| 87 | if (!chgCookieState) cookieState = !cookieState ; |
||
| 88 | |||
| 89 | if (cookieState) { |
||
| 90 | items.hide(); |
||
| 91 | lnk.text("'.dol_escape_js($langs->transnoentitiesnoconv("ShowSocialNetworks")).'..."); |
||
| 92 | if (chgCookieState) { document.cookie = "DOLUSER_SOCIALNETWORKS_SHOW=false; SameSite=Strict"}; |
||
| 93 | } else { |
||
| 94 | items.show(); |
||
| 95 | lnk.text("'.dol_escape_js($langs->transnoentitiesnoconv("HideSocialNetworks")).'..."); |
||
| 96 | if (chgCookieState) { document.cookie = "DOLUSER_SOCIALNETWORKS_SHOW=true; SameSite=Strict";} |
||
| 103 |