| Conditions | 91 | 
| Paths | 32 | 
| Total Lines | 152 | 
| Code Lines | 70 | 
| 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  | 
            ||
| 15 | static function selectSearchBox()  | 
            ||
| 16 |     { | 
            ||
| 17 |         if (!isset($usedbyinclude) || empty($usedbyinclude)) { | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 18 |             if (!defined('NOTOKENRENEWAL')) { | 
            ||
| 19 |                 define('NOTOKENRENEWAL', 1); // Disables token renewal | 
            ||
| 20 | }  | 
            ||
| 21 |             if (!defined('NOREQUIREMENU')) { | 
            ||
| 22 |                 define('NOREQUIREMENU', '1'); | 
            ||
| 23 | }  | 
            ||
| 24 |             if (!defined('NOREQUIREHTML')) { | 
            ||
| 25 |                 define('NOREQUIREHTML', '1'); | 
            ||
| 26 | }  | 
            ||
| 27 |             if (!defined('NOREQUIREAJAX')) { | 
            ||
| 28 |                 define('NOREQUIREAJAX', '1'); | 
            ||
| 29 | }  | 
            ||
| 30 |             if (!defined('NOREDIRECTBYMAINTOLOGIN')) { | 
            ||
| 31 |                 define('NOREDIRECTBYMAINTOLOGIN', '1'); | 
            ||
| 32 | }  | 
            ||
| 33 | |||
| 34 | $res = @include '../../main.inc.php';  | 
            ||
| 35 |             if ($res == 'ERROR_NOT_LOGGED') { | 
            ||
| 36 |                 $langs->load("other"); | 
            ||
| 37 |                 $arrayresult['jumptologin'] = array('img' => 'object_generic', 'label' => $langs->trans("JumpToLogin"), 'text' => '<span class="fa fa-sign-in"></span> ' . $langs->trans("JumpToLogin"), 'url' => DOL_URL_ROOT . '/index.php'); | 
            ||
| 38 | print json_encode($arrayresult);  | 
            ||
| 39 | /*  | 
            ||
| 40 | if (is_object($db))  | 
            ||
| 41 | $db->close();  | 
            ||
| 42 | */  | 
            ||
| 43 | exit;  | 
            ||
| 44 | }  | 
            ||
| 45 | }  | 
            ||
| 46 | |||
| 47 | // include_once DOL_DOCUMENT_ROOT . '/core/lib/json.lib.php';  | 
            ||
| 48 | //global Globals::$hookManager;  | 
            ||
| 49 |         Globals::$hookManager->initHooks(array('searchform')); | 
            ||
| 50 | |||
| 51 |         $search_boxvalue = DolUtils::GETPOST('q', 'none'); | 
            ||
| 52 | |||
| 53 | $arrayresult = array();  | 
            ||
| 54 | |||
| 55 | // Define $searchform  | 
            ||
| 56 | |||
| 57 |         if (!empty($conf->adherent->enabled) && empty($conf->global->MAIN_SEARCHFORM_ADHERENT_DISABLED) && $user->rights->adherent->lire) { | 
            ||
| 58 |             $arrayresult['searchintomember'] = array('position' => 8, 'shortcut' => 'M', 'img' => 'object_user', 'label' => $langs->trans("SearchIntoMembers", $search_boxvalue), 'text' => img_picto('', 'object_user') . ' ' . $langs->trans("SearchIntoMembers", $search_boxvalue), 'url' => DOL_URL_ROOT . '/adherents/list.php' . ($search_boxvalue ? '?sall=' . urlencode($search_boxvalue) : '')); | 
            ||
| 59 | }  | 
            ||
| 60 | |||
| 61 |         if (((!empty($conf->societe->enabled) && (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) || empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))) || !empty($conf->fournisseur->enabled)) && empty($conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED) && $user->rights->societe->lire) { | 
            ||
| 62 |             $arrayresult['searchintothirdparty'] = array('position' => 10, 'shortcut' => 'T', 'img' => 'object_company', 'label' => $langs->trans("SearchIntoThirdparties", $search_boxvalue), 'text' => img_picto('', 'object_company') . ' ' . $langs->trans("SearchIntoThirdparties", $search_boxvalue), 'url' => DOL_URL_ROOT . '/societe/list.php' . ($search_boxvalue ? '?sall=' . urlencode($search_boxvalue) : '')); | 
            ||
| 63 | }  | 
            ||
| 64 | |||
| 65 |         if (!empty($conf->societe->enabled) && empty($conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED) && $user->rights->societe->lire) { | 
            ||
| 66 |             $arrayresult['searchintocontact'] = array('position' => 15, 'shortcut' => 'A', 'img' => 'object_contact', 'label' => $langs->trans("SearchIntoContacts", $search_boxvalue), 'text' => img_picto('', 'object_contact') . ' ' . $langs->trans("SearchIntoContacts", $search_boxvalue), 'url' => DOL_URL_ROOT . '/contact/list.php' . ($search_boxvalue ? '?sall=' . urlencode($search_boxvalue) : '')); | 
            ||
| 67 | }  | 
            ||
| 68 | |||
| 69 |         if (((!empty($conf->product->enabled) && $user->rights->produit->lire) || (!empty($conf->service->enabled) && $user->rights->service->lire)) && empty($conf->global->MAIN_SEARCHFORM_PRODUITSERVICE_DISABLED)) { | 
            ||
| 70 |             $arrayresult['searchintoproduct'] = array('position' => 30, 'shortcut' => 'P', 'img' => 'object_product', 'label' => $langs->trans("SearchIntoProductsOrServices", $search_boxvalue), 'text' => img_picto('', 'object_product') . ' ' . $langs->trans("SearchIntoProductsOrServices", $search_boxvalue), 'url' => DOL_URL_ROOT . '/product/list.php' . ($search_boxvalue ? '?sall=' . urlencode($search_boxvalue) : '')); | 
            ||
| 71 | }  | 
            ||
| 72 | |||
| 73 |         if (!empty($conf->projet->enabled) && empty($conf->global->MAIN_SEARCHFORM_PROJECT_DISABLED) && $user->rights->projet->lire) { | 
            ||
| 74 |             $arrayresult['searchintoprojects'] = array('position' => 40, 'shortcut' => 'Q', 'img' => 'object_projectpub', 'label' => $langs->trans("SearchIntoProjects", $search_boxvalue), 'text' => img_picto('', 'object_projectpub') . ' ' . $langs->trans("SearchIntoProjects", $search_boxvalue), 'url' => DOL_URL_ROOT . '/projet/list.php' . ($search_boxvalue ? '?search_all=' . urlencode($search_boxvalue) : '')); | 
            ||
| 75 | }  | 
            ||
| 76 | |||
| 77 |         if (!empty($conf->projet->enabled) && empty($conf->global->MAIN_SEARCHFORM_TASK_DISABLED) && $user->rights->projet->lire) { | 
            ||
| 78 |             $arrayresult['searchintotasks'] = array('position' => 45, 'img' => 'object_task', 'label' => $langs->trans("SearchIntoTasks", $search_boxvalue), 'text' => img_picto('', 'object_task') . ' ' . $langs->trans("SearchIntoTasks", $search_boxvalue), 'url' => DOL_URL_ROOT . '/projet/tasks/list.php' . ($search_boxvalue ? '?search_all=' . urlencode($search_boxvalue) : '')); | 
            ||
| 79 | }  | 
            ||
| 80 | |||
| 81 |         if (!empty($conf->propal->enabled) && empty($conf->global->MAIN_SEARCHFORM_CUSTOMER_PROPAL_DISABLED) && $user->rights->propal->lire) { | 
            ||
| 82 |             $arrayresult['searchintopropal'] = array('position' => 60, 'img' => 'object_propal', 'label' => $langs->trans("SearchIntoCustomerProposals", $search_boxvalue), 'text' => img_picto('', 'object_propal') . ' ' . $langs->trans("SearchIntoCustomerProposals", $search_boxvalue), 'url' => DOL_URL_ROOT . '/comm/propal/list.php' . ($search_boxvalue ? '?sall=' . urlencode($search_boxvalue) : '')); | 
            ||
| 83 | }  | 
            ||
| 84 | |||
| 85 |         if (!empty($conf->commande->enabled) && empty($conf->global->MAIN_SEARCHFORM_CUSTOMER_ORDER_DISABLED) && $user->rights->commande->lire) { | 
            ||
| 86 |             $arrayresult['searchintoorder'] = array('position' => 70, 'img' => 'object_order', 'label' => $langs->trans("SearchIntoCustomerOrders", $search_boxvalue), 'text' => img_picto('', 'object_order') . ' ' . $langs->trans("SearchIntoCustomerOrders", $search_boxvalue), 'url' => DOL_URL_ROOT . '/commande/list.php' . ($search_boxvalue ? '?sall=' . urlencode($search_boxvalue) : '')); | 
            ||
| 87 | }  | 
            ||
| 88 | |||
| 89 |         if (!empty($conf->expedition->enabled) && empty($conf->global->MAIN_SEARCHFORM_CUSTOMER_SHIPMENT_DISABLED) && $user->rights->expedition->lire) { | 
            ||
| 90 |             $arrayresult['searchintoshipment'] = array('position' => 80, 'img' => 'object_sending', 'label' => $langs->trans("SearchIntoCustomerShipments", $search_boxvalue), 'text' => img_picto('', 'object_sending') . ' ' . $langs->trans("SearchIntoCustomerShipments", $search_boxvalue), 'url' => DOL_URL_ROOT . '/expedition/list.php' . ($search_boxvalue ? '?sall=' . urlencode($search_boxvalue) : '')); | 
            ||
| 91 | }  | 
            ||
| 92 | |||
| 93 |         if (!empty($conf->facture->enabled) && empty($conf->global->MAIN_SEARCHFORM_CUSTOMER_INVOICE_DISABLED) && $user->rights->facture->lire) { | 
            ||
| 94 |             $arrayresult['searchintoinvoice'] = array('position' => 90, 'img' => 'object_bill', 'label' => $langs->trans("SearchIntoCustomerInvoices", $search_boxvalue), 'text' => img_picto('', 'object_bill') . ' ' . $langs->trans("SearchIntoCustomerInvoices", $search_boxvalue), 'url' => DOL_URL_ROOT . '/compta/facture/list.php' . ($search_boxvalue ? '?sall=' . urlencode($search_boxvalue) : '')); | 
            ||
| 95 | }  | 
            ||
| 96 | |||
| 97 |         if (!empty($conf->supplier_proposal->enabled) && empty($conf->global->MAIN_SEARCHFORM_SUPPLIER_PROPAL_DISABLED) && $user->rights->supplier_proposal->lire) { | 
            ||
| 98 |             $arrayresult['searchintosupplierpropal'] = array('position' => 100, 'img' => 'object_propal', 'label' => $langs->trans("SearchIntoSupplierProposals", $search_boxvalue), 'text' => img_picto('', 'object_propal') . ' ' . $langs->trans("SearchIntoSupplierProposals", $search_boxvalue), 'url' => DOL_URL_ROOT . '/supplier_proposal/list.php' . ($search_boxvalue ? '?sall=' . urlencode($search_boxvalue) : '')); | 
            ||
| 99 | }  | 
            ||
| 100 | |||
| 101 |         if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_SEARCHFORM_SUPPLIER_ORDER_DISABLED) && $user->rights->fournisseur->commande->lire) { | 
            ||
| 102 |             $arrayresult['searchintosupplierorder'] = array('position' => 110, 'img' => 'object_order', 'label' => $langs->trans("SearchIntoSupplierOrders", $search_boxvalue), 'text' => img_picto('', 'object_order') . ' ' . $langs->trans("SearchIntoSupplierOrders", $search_boxvalue), 'url' => DOL_URL_ROOT . '/fourn/commande/list.php' . ($search_boxvalue ? '?search_all=' . urlencode($search_boxvalue) : '')); | 
            ||
| 103 | }  | 
            ||
| 104 | |||
| 105 |         if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_SEARCHFORM_SUPPLIER_INVOICE_DISABLED) && $user->rights->fournisseur->facture->lire) { | 
            ||
| 106 |             $arrayresult['searchintosupplierinvoice'] = array('position' => 120, 'img' => 'object_bill', 'label' => $langs->trans("SearchIntoSupplierInvoices", $search_boxvalue), 'text' => img_picto('', 'object_bill') . ' ' . $langs->trans("SearchIntoSupplierInvoices", $search_boxvalue), 'url' => DOL_URL_ROOT . '/fourn/facture/list.php' . ($search_boxvalue ? '?sall=' . urlencode($search_boxvalue) : '')); | 
            ||
| 107 | }  | 
            ||
| 108 | |||
| 109 |         if (!empty($conf->contrat->enabled) && empty($conf->global->MAIN_SEARCHFORM_CONTRACT_DISABLED) && $user->rights->contrat->lire) { | 
            ||
| 110 |             $arrayresult['searchintocontract'] = array('position' => 130, 'img' => 'object_contract', 'label' => $langs->trans("SearchIntoContracts", $search_boxvalue), 'text' => img_picto('', 'object_contract') . ' ' . $langs->trans("SearchIntoContracts", $search_boxvalue), 'url' => DOL_URL_ROOT . '/contrat/list.php' . ($search_boxvalue ? '?sall=' . urlencode($search_boxvalue) : '')); | 
            ||
| 111 | }  | 
            ||
| 112 | |||
| 113 |         if (!empty($conf->ficheinter->enabled) && empty($conf->global->MAIN_SEARCHFORM_FICHINTER_DISABLED) && $user->rights->ficheinter->lire) { | 
            ||
| 114 |             $arrayresult['searchintointervention'] = array('position' => 140, 'img' => 'object_intervention', 'label' => $langs->trans("SearchIntoInterventions", $search_boxvalue), 'text' => img_picto('', 'object_intervention') . ' ' . $langs->trans("SearchIntoInterventions", $search_boxvalue), 'url' => DOL_URL_ROOT . '/fichinter/list.php' . ($search_boxvalue ? '?sall=' . urlencode($search_boxvalue) : '')); | 
            ||
| 115 | }  | 
            ||
| 116 | |||
| 117 | // HR  | 
            ||
| 118 |         if (!empty($conf->user->enabled) && empty($conf->global->MAIN_SEARCHFORM_USER_DISABLED) && $user->rights->user->user->lire) { | 
            ||
| 119 |             $arrayresult['searchintouser'] = array('position' => 200, 'shortcut' => 'U', 'img' => 'object_user', 'label' => $langs->trans("SearchIntoUsers", $search_boxvalue), 'text' => img_picto('', 'object_user') . ' ' . $langs->trans("SearchIntoUsers", $search_boxvalue), 'url' => DOL_URL_ROOT . '/user/list.php' . ($search_boxvalue ? '?sall=' . urlencode($search_boxvalue) : '')); | 
            ||
| 120 | }  | 
            ||
| 121 | |||
| 122 |         if (!empty($conf->expensereport->enabled) && empty($conf->global->MAIN_SEARCHFORM_EXPENSEREPORT_DISABLED) && $user->rights->expensereport->lire) { | 
            ||
| 123 |             $arrayresult['searchintoexpensereport'] = array('position' => 210, 'img' => 'object_trip', 'label' => $langs->trans("SearchIntoExpenseReports", $search_boxvalue), 'text' => img_picto('', 'object_trip') . ' ' . $langs->trans("SearchIntoExpenseReports", $search_boxvalue), 'url' => DOL_URL_ROOT . '/expensereport/list.php?mainmenu=hrm' . ($search_boxvalue ? '&sall=' . urlencode($search_boxvalue) : '')); | 
            ||
| 124 | }  | 
            ||
| 125 | |||
| 126 |         if (!empty($conf->holiday->enabled) && empty($conf->global->MAIN_SEARCHFORM_HOLIDAY_DISABLED) && $user->rights->holiday->read) { | 
            ||
| 127 |             $arrayresult['searchintoleaves'] = array('position' => 220, 'img' => 'object_holiday', 'label' => $langs->trans("SearchIntoLeaves", $search_boxvalue), 'text' => img_picto('', 'object_holiday') . ' ' . $langs->trans("SearchIntoLeaves", $search_boxvalue), 'url' => DOL_URL_ROOT . '/holiday/list.php?mainmenu=hrm' . ($search_boxvalue ? '&sall=' . urlencode($search_boxvalue) : '')); | 
            ||
| 128 | }  | 
            ||
| 129 | |||
| 130 | |||
| 131 | /* Do we really need this. We already have a select for users, and we should be able to filter into user list on employee flag  | 
            ||
| 132 | if (! empty($conf->hrm->enabled) && ! empty($conf->global->MAIN_SEARCHFORM_EMPLOYEE) && $user->rights->hrm->employee->read)  | 
            ||
| 133 |           { | 
            ||
| 134 |           $langs->load("hrm"); | 
            ||
| 135 |           $searchform.=printSearchForm(DOL_URL_ROOT.'/hrm/employee/list.php', DOL_URL_ROOT.'/hrm/employee/list.php', $langs->trans("Employees"), 'employee', 'search_all', 'M', 'searchleftemployee', img_object('','user')); | 
            ||
| 136 | }  | 
            ||
| 137 | */  | 
            ||
| 138 | |||
| 139 | // Execute hook addSearchEntry  | 
            ||
| 140 |         $parameters = array('search_boxvalue' => $search_boxvalue, 'arrayresult' => $arrayresult); | 
            ||
| 141 |         $reshook = Globals::$hookManager->executeHooks('addSearchEntry', $parameters); | 
            ||
| 142 |         if (empty($reshook)) { | 
            ||
| 143 | $arrayresult = array_merge($arrayresult, Globals::$hookManager->resArray);  | 
            ||
| 144 | } else  | 
            ||
| 145 | $arrayresult = Globals::$hookManager->resArray;  | 
            ||
| 146 | |||
| 147 | // This allow to keep a search entry to the top  | 
            ||
| 148 |         if (!empty($conf->global->DEFAULT_SEARCH_INTO_MODULE)) { | 
            ||
| 149 | $key = 'searchinto' . $conf->global->DEFAULT_SEARCH_INTO_MODULE;  | 
            ||
| 150 | if (array_key_exists($key, $arrayresult))  | 
            ||
| 151 | $arrayresult[$key]['position'] = -10;  | 
            ||
| 152 | }  | 
            ||
| 153 | |||
| 154 | // Sort on position  | 
            ||
| 155 | $arrayresult = DolUtils::dol_sort_array($arrayresult, 'position');  | 
            ||
| 156 | |||
| 157 | // Print output if called by ajax or do nothing (var $arrayresult will be used) if called by an include  | 
            ||
| 158 |         if (!isset($usedbyinclude) || empty($usedbyinclude)) { | 
            ||
| 159 | print json_encode($arrayresult);  | 
            ||
| 160 | /*  | 
            ||
| 161 | if (is_object($db))  | 
            ||
| 162 | $db->close();  | 
            ||
| 163 | */  | 
            ||
| 164 | }  | 
            ||
| 165 | |||
| 166 | return $arrayresult;  | 
            ||
| 167 | }  | 
            ||
| 169 |